Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress短代码只能在文章中使用,不能在页面中使用。自定义主题_Php_Wordpress_Wordpress Theming - Fatal编程技术网

Php Wordpress短代码只能在文章中使用,不能在页面中使用。自定义主题

Php Wordpress短代码只能在文章中使用,不能在页面中使用。自定义主题,php,wordpress,wordpress-theming,Php,Wordpress,Wordpress Theming,我正在为一个朋友创建一个主题,但由于某些原因,我无法在页面中使用短代码。他们只在岗位上工作 目前,我的page.php文件非常简单: <?php get_header(); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); echo '<div class="hero-unit"><div class="container"><h1>'.ge

我正在为一个朋友创建一个主题,但由于某些原因,我无法在页面中使用短代码。他们只在岗位上工作

目前,我的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()
显示的,这是一个返回内容的函数,而不应用默认过滤器(
wpcautop
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;
?>


完美。谢谢你的帮助,厌倦@用户1636130如果有机会,请将其标记为解决方案!我还用固定代码更新了它,它使用
标题()
内容()
而不是
获取标题()
获取内容()
。谢谢你的时间:)我会尽快标记它。你也可以这样做
$content=获取内容();echo应用_过滤器('the_content',$content)
将通过
内容()上使用的默认筛选器,传递
获取内容()返回的未过滤内容。