Wordpress短代码无法正常工作

Dav*_*ave 4 wordpress shortcode

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

我理解如何制作短代码,但是当WP将其吐出来展示时,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...
    }
Run Code Online (Sandbox Code Playgroud)

kea*_*tch 11

好的,试试这个

 $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++;
Run Code Online (Sandbox Code Playgroud)

Wordpress会记录您的内容并对其应用过滤器.您必须注册过滤器并解析您的内容.

如果你的主题没有显示你的短代码,可能你输出帖子的内容而不让Wordpress过滤它.

为帖子调用函数get_the_content()不会为短代码运行过滤器(如果有的话).

申请

<?php apply_filters('the_content',get_the_content( $more_link_text, $stripteaser, $more_file )) ?>
Run Code Online (Sandbox Code Playgroud)

参考:http://codex.wordpress.org/Function_Reference/get_the_content

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