Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress短代码不工作_Wordpress_Shortcode - Fatal编程技术网

Wordpress短代码不工作

Wordpress短代码不工作,wordpress,shortcode,Wordpress,Shortcode,我为wordpress构建了一个非常独特且javascript密集的主题,现在短代码不起作用。我没有安装任何插件,所以不是这样。我从wordpress模板文件中删除了使用短代码(即:[gallery])所需的内容 我知道如何制作短代码,但当WP将其吐出以供显示时,它是如何接收您的帖子并替换“[gallery]”的 编辑: 以下是我目前正在处理的问题: $pagepull = $wpdb->get_results("SELECT * FROM $wpdb->posts WHER

我为wordpress构建了一个非常独特且javascript密集的主题,现在短代码不起作用。我没有安装任何插件,所以不是这样。我从wordpress模板文件中删除了使用短代码(即:[gallery])所需的内容

我知道如何制作短代码,但当WP将其吐出以供显示时,它是如何接收您的帖子并替换“[gallery]”的

编辑: 以下是我目前正在处理的问题:

    $pagepull = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish' ORDER BY menu_order", ARRAY_A);
    $i = 1;
    foreach ($pagepull as $single_page){
     echo "<div class=\"section\"><ul><li class=\"sub\" id=\"" . $i  . "\"><div class=\"insection\">";
         echo $single_page['post_content'];
$i++;
// more code that is irrelevant...
// more code that is irrelevant...
// more code that is irrelevant...
    }
$pagepull=$wpdb->get_results(“从$wpdb中选择*->posts,其中post_type='page',post_status='publish'按菜单顺序排列”,数组A);
$i=1;
foreach($pagepull作为$single_page){
echo“
  • ”; echo$single_页面['post_content']; $i++; //更多不相关的代码。。。 //更多不相关的代码。。。 //更多不相关的代码。。。 }
好的,试试这个

 $pagepull = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish' ORDER BY menu_order", ARRAY_A);
    $i = 1;
    foreach ($pagepull as $single_page){
     echo "<div class=\"section\"><ul><li class=\"sub\" id=\"" . $i  . "\"><div class=\"insection\">";
         echo apply_filters('the_content',$single_page['post_content']);
$i++;
$pagepull=$wpdb->get_results(“从$wpdb中选择*->posts,其中post_type='page',post_status='publish'按菜单顺序排列”,数组A);
$i=1;
foreach($pagepull作为$single_page){
echo“
  • ”; echo apply_过滤器('the_content',$single_page['post_content']); $i++;
Wordpress获取您的内容并对其应用筛选器。您必须注册筛选器并允许解析您的内容

如果你的主题没有显示你的短代码,很可能你在没有让Wordpress过滤的情况下输出了文章的内容

为帖子调用函数get_the_content(),不会对短代码(如果有)运行筛选器

申请

<?php apply_filters('the_content',get_the_content( $more_link_text, $stripteaser, $more_file )) ?>

参考:


注意:许多插件使用内容注册过滤器以实现短代码!

我的解决方案正在替换

<?= get_the_content() ?>


正如keatch已经提到的,它在返回内容之前应用过滤器


如果您希望变量中包含内容,请使用此选项:

ob_start();
the_content();
$content = ob_get_clean();
现在,您只需执行echo$content;或使用regex或任何您想要使内容看起来像您想要的内容的操作。

请使用

ob_start();
在功能和使用的开始阶段

return ob_get_clean();
在关闭函数之前

希望这对你有帮助

干杯

我也有同样的问题

短代码取决于WP循环,但这是另一个问题。长话短说,我在应该显示短代码的页面上添加了
the_post();
(例如
articles.php


另外,请确保您正在使用
the_content()
来显示文本(例如,使用
$post->post_data
不会显示短代码)。

谢谢您的评论!您有没有可能对我的新编辑发表评论?请看下面我的答案!简短回答:您正在使用原始内容($single_page['post_content'))而不是过滤的过滤器:应用内容过滤器。echo应用内容过滤器('the_content',$single_page['post_content']);
return ob_get_clean();