php - Wordpress 短代码仅适用于帖子,不适用于页面。自定义主题

标签 php wordpress wordpress-theming

我正在为 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() 显示,这是一个返回内容但不应用默认过滤器(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;
?>

关于php - Wordpress 短代码仅适用于帖子,不适用于页面。自定义主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20568145/

相关文章:

php - 在 Symfony 2 Controller 中抽象通用功能的正确方法是什么

wordpress - 在单个 url 中组合多个自定义用户分类

Python Wordpress-XMLRPC : ServerConnectionError: <ProtocolError 409 Conflict>

css - 如何在 woocommerce 中为产品列表制作固定列?

css - 更改页眉和页脚中的背景颜色 Clean Retina WordPress 主题

php - 这是我用于查看用户个人资料的 php

php - 使用 php (Raspberry Pi) 设置 cronjob

javascript - 循环遍历 Javascript 中从 PHP 获取的对象

wordpress - WP 全部导出 : how to pass exported data through PHP function

php - Wordpress 多站点和 Stripe 订阅?