Wordpress短代码仅适用于帖子,而非页面。自定义主题

时间:2013-12-13 13:50:24

标签: php wordpress wordpress-plugin wordpress-theming

我正在为朋友制作一个主题,但有些原因我无法在Pages中使用短代码。他们只在帖子中工作。

我的page.php文件目前非常简单:

<?php get_header(); ?>
<?php
if (have_posts()) :
    while (have_posts()) : the_post();
        echo '<div class="hero-unit"><div class="container"><h1>'.get_the_title().'</h1></div></div>';
        echo '<div class="container clearfix" id="main-content">'.get_the_content().'</div>';
    endwhile;
endif;
?>
<?php get_footer(); ?>

这工作正常,但只是将短代码显示为文本。 IE我试图使用短代码[wp_sitemap_page],页面只是在文本中呈现'[wp_sitemap_page]'。

可能是什么问题?

1 个答案:

答案 0 :(得分:8)

您的帖子内容是通过echo get_the_content()显示的,这是一个返回内容的功能,不会应用使用{{wpautopdo_shortcode等正常应用的默认过滤器the_content()<?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="hero-unit"><div class="container"><h1><?php the_title(); ?></h1></div></div> <div class="container clearfix" id="main-content"><?php the_content(); ?></div> <?php endwhile; endif; ?> 等1}}而不是。

这应该解决它:

{{1}}
相关问题