- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在我的 WordPress 网站上安装了 Elementor Pro,我正在编写一个自定义插件来执行一些操作并以编程方式创建一个新页面。我能够创建页面,但问题是,我想以编程方式在此新页面中插入一个 Elementor Widget。
我已经联系了 Elementor 支持人员,看看他们是否有任何意见要告诉我。但他们的回答是:
As much as I'd like to assist you with this, custom code/snippet or any guidance for this is beyond the scope of our support, given thatwe provide support for Elementor's existing features only.
那么我是否可以通过代码实现这一点,我的意思是将特定的 Elementor Widget 插入页面?
最佳答案
这不是最好的解决方案,但我会解释我是如何找到解决方法的。
对我来说,我尝试监视我的 WordPress 网站的数据库,以查看在使用 Elementor 创建新页面时发生的所有更改。我监控的表是:wp_posts
和 wp_postmeta
。请注意,如果您在安装 WordPress 时选择了不同的前缀,则 wp_
前缀可能会有所不同。
当您创建页面时,会在 wp_posts
表中插入一个具有 post_type
值 page
的新行。记下 post_id
的值(为了解释,让 post_id
为 123
)。
此页面的元数据将存储在 wp_postmeta
表中,这是 Elementor 存储与每个页面或帖子相关的数据的地方。使用 phpMyAdmin,我访问了该表并搜索了具有 post_id = 123
的记录(这里 123
是页面的 ID)。您可以像这样使用 phpMyAdmin 的 Search 选项卡(选择 wp_postmeta
表后):
或者,可以在 phpMyAdmin 的 SQL 选项卡 中运行这样的查询:
SELECT * FROM `wp_postmeta` WHERE `post_id` = 123
现在您将看到附加到我们页面的所有元数据(ID 123
)。
在我的例子中,我之前已经在 Elementor 中添加了一个小部件,用于此页面(ID 123
)。因此,如上图所示,它附加了一些元数据。
那个 _wp_page_template = page-fullwidth.php
在那里,因为我为我的页面的 模板属性 选择了 Full Width
:
这两个值似乎是让它理解页面是使用 Elementor 创建的:
_elementor_edit_mode = builder
_elementor_template_type = wp-page
所以我们绝对需要它。然后对于 Elementor 版本值:
_elementor_version = 2.9.14
_elementor_pro_version = 2.10.3
您可以使用常量:ELEMENTOR_VERSION
(如果您有 Elementor 插件的免费版本)和 ELEMENTOR_PRO_VERSION
(如果您有 Pro 版插件)。如果您安装了 Elementor 插件的相应版本(免费或专业版),则这些常量已经定义。
然后是重要的部分,Widget 的数据和布局相关数据似乎存储在 _elementor_data
和 _elementor_controls_usage
元键中。
_elementor_data
的值似乎是 JSON 字符串。所以你可以使用任何online JSON parser看看它有什么。我的情况是这样的:
[{"id":"2e0569b","elType":"section","settings":[],"elements":[{"id":"e2a6dbb","elType":"column","settings":{"_column_size":100,"_inline_size":null},"elements":[{"id":"441552a","elType":"widget","settings":{"tag_ids":"21"},"elements":[],"widgetType":"listings_grid_new"}],"isInner":false}],"isInner":false}]
解析后如下所示:
[
{
"id": "2e0569b",
"elType": "section",
"settings": [],
"elements": [
{
"id": "e2a6dbb",
"elType": "column",
"settings": {
"_column_size": 100,
"_inline_size": null
},
"elements": [
{
"id": "441552a",
"elType": "widget",
"settings": {
"tag_ids": "21"
},
"elements": [],
"widgetType": "listings_grid_new"
}
],
"isInner": false
}
],
"isInner": false
}
]
由于我之前将该小部件添加到我的页面,并将标签 ID 输入框的值设置为 21
(通过 Elementor 编辑器),因此我知道我必须传递新值来替换该 21
.
然后是 _elementor_controls_usage
元键。而它的值(value)是这样的:
a:3:{s:17:"listings_grid_new";a:3:{s:5:"count";i:1;s:15:"control_percent";i:1;s:8:"controls";a:1:{s:7:"content";a:1:{s:13:"section_query";a:2:{s:7:"loc_ids";i:1;s:7:"tag_ids";i:1;}}}}s:6:"column";a:3:{s:5:"count";i:1;s:15:"control_percent";i:0;s:8:"controls";a:1:{s:6:"layout";a:1:{s:6:"layout";a:1:{s:12:"_inline_size";i:1;}}}}s:7:"section";a:3:{s:5:"count";i:1;s:15:"control_percent";i:0;s:8:"controls";a:0:{}}}
它是序列化的数据。您可以使用任何 online tool to unserialize那个数据。这是我的反序列化后的样子:
array (
'listings_grid_new' =>
array (
'count' => 1,
'control_percent' => 1,
'controls' =>
array (
'content' =>
array (
'section_query' =>
array (
'loc_ids' => 1,
'tag_ids' => 1,
),
),
),
),
'column' =>
array (
'count' => 1,
'control_percent' => 0,
'controls' =>
array (
'layout' =>
array (
'layout' =>
array (
'_inline_size' => 1,
),
),
),
),
'section' =>
array (
'count' => 1,
'control_percent' => 0,
'controls' =>
array (
),
),
)
它看起来基本上是布局相关的数据。所以我想不做任何编辑这个值,并按原样使用它。
让我们做最后一件事
为了创建页面,我使用了 wp_insert_post()方法,它在插入后返回新的 page_id
。创建页面后,我使用了 update_post_meta()方法,传递此 page_id
并附加元数据。
我的最终代码如下所示:
//-- set the new page arguments
$new_page_args = array(
'post_type' => 'page', //-- this is of type 'page'
'post_title' => 'My Dynamic Page', //-- title of the page
'post_status' => 'publish' //-- publish the page
);
//-- insert the page
$new_page_id = wp_insert_post( $new_page_args );
if( is_wp_error( $new_page_id ) )
{
echo 'Unable to create the page!';
die;
}
if( defined( 'ELEMENTOR_VERSION' ) ) //-- if FREE version of Elementor plugin is installed
{
update_post_meta( $new_page_id, '_elementor_version', ELEMENTOR_VERSION );
}
if( defined( 'ELEMENTOR_PRO_VERSION' ) ) //-- if PRO version of Elementor plugin is installed
{
update_post_meta( $new_page_id, '_elementor_pro_version', ELEMENTOR_PRO_VERSION );
}
update_post_meta( $new_page_id, '_wp_page_template', 'page-fullwidth.php' ); //-- for using full width template
//-- for Elementor
update_post_meta( $new_page_id, '_elementor_edit_mode', 'builder' );
update_post_meta( $new_page_id, '_elementor_template_type', 'wp-page' );
//-- Elementor layout
update_post_meta( $new_page_id, '_elementor_controls_usage', 'a:3:{s:17:"listings_grid_new";a:3:{s:5:"count";i:1;s:15:"control_percent";i:1;s:8:"controls";a:1:{s:7:"content";a:1:{s:13:"section_query";a:2:{s:7:"loc_ids";i:1;s:7:"tag_ids";i:1;}}}}s:6:"column";a:3:{s:5:"count";i:1;s:15:"control_percent";i:0;s:8:"controls";a:1:{s:6:"layout";a:1:{s:6:"layout";a:1:{s:12:"_inline_size";i:1;}}}}s:7:"section";a:3:{s:5:"count";i:1;s:15:"control_percent";i:0;s:8:"controls";a:0:{}}}' );
$tag_id = '56'; //-- new value
//-- Elementor data ( I have injected the new $tag_id value in the string )
update_post_meta( $new_page_id, '_elementor_data', '[{"id":"2e0569b","elType":"section","settings":[],"elements":[{"id":"e2a6dbb","elType":"column","settings":{"_column_size":100,"_inline_size":null},"elements":[{"id":"441552a","elType":"widget","settings":{"tag_ids":"'. $tag_id .'"},"elements":[],"widgetType":"listings_grid_new"}],"isInner":false}],"isInner":false}]' );
请记住,这不是完美的解决方案。但我解释了我是如何找到解决这个问题的方法的。
也许其他人会发布更好的解决方案。 ;)
关于WordPress - 以编程方式在页面中插入 Elementor 小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63898766/
Elementor Pro 有一个新的小部件,视频播放列表。它将参数附加到 URL,如下所示:http://aaronpenton.net/ampcreative/vip/about-vip/?pla
我正在我的 WordPress 网站上的 Elementor 中创建页脚。我的页脚内容居中。现在我想在页脚中添加 iconlist widget。但是,它并没有按照我想要的方式居中。我希望图标在左侧保
我在使用 Elementor Wordpress 页面生成器时遇到了一个奇怪的问题。 创建自定义短代码并将其插入任何页面位置后,它也会显示在页面顶部,但仅在编辑模式下显示。 页面顶部: 我要插入短代码
我曾试图解决我的问题,但不幸的是我仍然没有找到正确的解决方案。 我想要的只是在第 1 列的左侧有白色背景,在第 2 列的右侧有灰色背景。 但是我在 Column 选项中找不到需要的属性(我不确定是否有
我正在做一个自定义 Elementor Widget(在 Wordpress 中),我正在尝试让一个 Select 控件将来自另一个控件的数据作为选项。这是我的代码 $property_types
我在我的 WordPress 网站上安装了 Elementor Pro,我正在编写一个自定义插件来执行一些操作并以编程方式创建一个新页面。我能够创建页面,但问题是,我想以编程方式在此新页面中插入一个
我想先保留我的自定义类别。有人可以提供帮助。 看到这个我的代码, function add_elementor_widget_categories( $elements_manager ) {
我想在单击我在 elementor 页面中添加的每个按钮时在全屏上添加灯箱弹出窗口。这可能吗?我已经设置了按钮 id,但不知道如何在插件中使用它 最佳答案 使用此插件(弹出窗口制作器):https:/
我一直在尝试弄清楚 Wordpress 中的 Elementor(和 Elementor Pro)插件正在做什么以使其脚本最后加载到正文中,因为我的插件脚本需要在这些之后加载。它需要在结束 body
我在 Elementor 中使用粘性菜单。在桌面上没问题。在移动设备上,粘性标题/菜单覆盖了第一个元素,但是当我滚动时,元素/页面跳下并留下空白。当我修复间距以使其最初可见时,会有更多的空白。如何停止
不确定这是否只是 Elementor 全宽模板的问题,但它似乎覆盖了主题 header.php。我尝试通过使用 elementor 自定义代码功能来实现我的目标,但它在标记中间的某个位置添加了我的代码
我正在为 WordPress 媒体库编写一个扩展,我需要向媒体库添加一个按钮,点击该按钮将打开一个模式窗口,用户可以从中选择图片。 看截图 screenshot 1 screenshot 2 目前,在
我想从自定义代码(HTML、CSS、Javascript)调用 Elementor Popup。有谁知道这是怎么做到的吗?提前致谢! 最佳答案 以下是通过 javascript 调用弹出窗口的方法:
我正在尝试更改由大约 400 个页面上存在的元素或页面构建器插件创建的页面中的值/文本。我已经用正确的值编辑了数据库 (wp_posts),但它在前端没有改变。这些值仍然是页面上的旧值。似乎某处正在缓
希望大家都过得好! 我正在通过 Elementor 插件在 WordPress 中创建一个网站。我在按钮上遇到了一个奇怪的问题。按钮有换行符 ,即使我没有在那里添加它。 但另一方面,该按钮在 Ele
我是 的新手WordPress , 但我有很好的经验 java 发展。我开发了一个小 WordPress 网站使用 海洋WP , 元素 .在主页中,我需要显示我网站中的注册成员(member)数量。
想要在简单的编辑器中切换我的 elementor 构建器界面,例如我网站上的旧 Html 编辑器 tellthebell * 由于这个构建器,我的网站加载缓慢。想知道我的内容是否会丢失或者只是设计会改
在 Elementor 中,默认情况下,如果我们在小部件内添加布局,我们可以看到小部件和布局(小部件的子级)之间存在间隙或空间,如下图所示: 有什么方法可以删除它,因为我仍然找不到它。 最佳答案 默认
在 Elementor 中,默认情况下,如果我们在小部件内添加布局,我们可以看到小部件和布局(小部件的子级)之间存在间隙或空间,如下图所示: 有什么方法可以删除它,因为我仍然找不到它。 最佳答案 默认
作为我的网站http://newwebsite.outfit24.com.au (仍在构建中)是基于图像的,我希望标题文本颜色发生变化,以便它从背景(深色和浅色图像)中脱颖而出。我已经使用 Eleme
我是一名优秀的程序员,十分优秀!