我正在为 friend 构建主题,但由于某些原因我无法在 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]”。
可能是什么问题?
最佳答案
您的帖子内容通过 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;
?>
关于php - Wordpress 短代码仅适用于帖子,不适用于页面。自定义主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20568145/