use*_*130 5 php wordpress wordpress-theming wordpress-plugin
我正在为朋友建立一个主题,但有些原因我无法在Pages中使用短代码.他们只在Posts工作.
我的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(); ?>
Run Code Online (Sandbox Code Playgroud)
这工作正常,但只是将短代码显示为文本.IE我试图使用短代码[wp_sitemap_page]页面只是在文本中呈现'[wp_sitemap_page]'.
可能是什么问题?
您的帖子内容显示通过echo get_the_content()这就是返回的内容不应用默认筛选器(一个功能wpautop,do_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;
?>
Run Code Online (Sandbox Code Playgroud)