显示在CPT快捷代码下方的WP编辑器中的内容

时间:2012-06-05 作者:JohnG

Possible Duplicate:
Shortcode always displaying at the top of the page

我开发了几个插件,通过一个短代码(通过WP\\u查询)获取CPT项目。我遇到的问题是,在调用shortcode之前在WP编辑器中输入的任何内容总是在shortcode数据之后输出。

编辑:

My regular content here
[shortcode]
more content here
页面输出:

shortcode data
My regular content here
more content here
这是我的快捷码查询

$defaults = apply_filters( \'arconix_faq_shortcode_query_args\',
    array(
    \'post_type\' => \'faq\',
            \'showposts\' => \'all\',
    \'order\' => \'ASC\',
    \'orderby\' => \'title\'
    )
);

extract( shortcode_atts( $defaults, $atts ) );

    /** Translate \'all\' to -1 for query terms */
    if( $showposts == "all" ) $showposts = "-1";

    /** Create a new query bsaed on our own arguments */
$faq_query = new WP_Query( array( \'post_type\' => $post_type, \'order\' => $order, \'orderby\' => $orderby, \'posts_per_page\' => $showposts ) );

    if( $faq_query->have_posts() ) : while ( $faq_query->have_posts() ) : $faq_query->the_post();

    echo \'<div id="post-\' . get_the_ID() .\'" class="arconix-faq-wrap">\';
    echo \'<div class="arconix-faq-title">\' . get_the_title() . \'</div>\';
        echo \'<div class="arconix-faq-content">\' . get_the_content() . \'</div>\';
        echo \'</div>\';

    endwhile; endif; wp_reset_postdata();
}
想法?

1 个回复
最合适的回答,由SO网友:Bainternet 整理而成

您的快捷码应该返回其输出,而不是回显,例如:

$defaults = apply_filters( \'arconix_faq_shortcode_query_args\',
    array(
    \'post_type\' => \'faq\',
            \'showposts\' => \'all\',
    \'order\' => \'ASC\',
    \'orderby\' => \'title\'
    )
);

extract( shortcode_atts( $defaults, $atts ) );

    /** Translate \'all\' to -1 for query terms */
    if( $showposts == "all" ) $showposts = "-1";

    /** Create a new query bsaed on our own arguments */
    $faq_query = new WP_Query( array( \'post_type\' => $post_type, \'order\' => $order, \'orderby\' => $orderby, \'posts_per_page\' => $showposts ) );
    $RetVal = \'\';
    if( $faq_query->have_posts() ) : while ( $faq_query->have_posts() ) : $faq_query->the_post();

    $RetVal .= \'<div id="post-\' . get_the_ID() .\'" class="arconix-faq-wrap">\';
    $RetVal .= \'<div class="arconix-faq-title">\' . get_the_title() . \'</div>\';
    $RetVal .= \'<div class="arconix-faq-content">\' . get_the_content() . \'</div>\';
    $RetVal .= \'</div>\';

    endwhile; endif; wp_reset_postdata();
}
return $RetVal;

结束

相关推荐

the_excerpt and shortcodes

我正在使用索引页上的\\u摘录。我还在我的每一篇文章的开头使用dropcap快捷码。在索引页面上,帖子不会显示周围带有dropcap快捷码的信件。如果我的帖子中有“Dog”一词,索引页会显示“og”。在使用\\u摘录时,如何使用短代码?短代码 function drcap ($atts, $content = null) { return \'<div class=\"dropcap\">\' . do_shortcode($content) . \'</div&g