分割通过“the_content()”获得的内容;在 WordPress 中
现在我正在使用以下插件 - 'shortcoder' 来允许我推送整个首页我的 WordPress 网站使用单个帖子。 以下是我的帖子的结构
[shortcode 1]
[shortcode 2]
[shortcode 3]
[shortcode 4]
[shortcode 5]
[shortcode 6]
- 现在这些都是静态的,仅包含 html 和 javascript 内容。这篇文章使用“the_content()”模板标签显示在我的index.php 上。
但现在我将从我的其他帖子中提取一些动态内容来代替其中一些短代码,这些短代码的逻辑将被硬编码在index.php 文件中。例如,
[shortcode 1] static
[shortcode 2] static
[shortcode 3] dynamic
[shortcode 4] static
[shortcode 5] dynamic
[shortcode 6] static
需要明确的是,所有静态部分都将通过短代码进行,但动态部分将硬编码在 index.php 文件中。 但是,由于串行顺序,此逻辑变得混乱。
我想以某种方式将通过“the_content()”传入的内容拆分为适当的静态部分。
抱歉发了这么长的帖子,但我希望有人能想出一个解决方案。
Right now I am using the following plugin- 'shortcoder' to allow me to push the entire frontpage of my wordpress site using a single post.
Following is the structure of my post-
[shortcode 1]
[shortcode 2]
[shortcode 3]
[shortcode 4]
[shortcode 5]
[shortcode 6]
Right now these are all static containing only html and javascript content. This post is getting displayed on my index.php using the 'the_content()' template tag.
But now I will be pulling some dynamic content from my other posts in place of some of these shortcodes whose logic will be hardcoded in the index.php file. For eg.-
[shortcode 1] static
[shortcode 2] static
[shortcode 3] dynamic
[shortcode 4] static
[shortcode 5] dynamic
[shortcode 6] static
Just to be clear all the static sections will come through the shortcode but the dynamic sections will be hardcoded in the index.php file.
However, because of the serial order this logic is getting messed up.
I want to somehow split up the content coming through 'the_content()' into the appropriate static sections.
Sorry for the long post but I hope someone can come up with a solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建自己的短代码来调用要运行的脚本。
例如,在您的
functions.php
文件中,您可以添加如下内容:现在,在您的帖子编辑器中,您可以添加自己的短代码与插件的交织在一起,例如:
所以,基本上,您' d 将您的插件用于静态代码,并使用您自己的短代码用于动态代码=)
我希望能帮助您或让您朝着正确的方向前进。让我知道!
You could create your own shortcode(s) to call the scripts you want to run.
For example, in your
functions.php
file you could add something like this:Now, in your post editor, you could add your own shortcode intertwined with the plugin's, such as:
So, basically, you'd be using your plugin for static code and your own shortcode for dynamic code =)
I hope that helps or gets you in the right direction. Let me know!
这就是我使用普通 phpexplode 解决问题的方法 -
我首先为所有短代码添加了“~”分隔符 -
然后使用以下代码分隔了短代码
-之后我所做的一切都在正确的位置回显了所需的变量在模板中-
This is how I solved my problem using normal php explode-
I first added the '~' separator for all my shortcodes like -
Then using the following code I separated the shortcodes-
After that all I did was echoed the required variables at the right spots in the template-