0

我目前正在学习如何制作 wordpress 主题,但不知何故标题标签被破坏了。出于某种原因,它在代码中添加了引号,并且代码正在页面本身上显示。我知道这会影响 WP 3.4 及更高版本,但我没有使用任何插件等。请问解决此问题的正确方法是什么?谢谢。我的 Wordpress 版本是 3.6。

问题

这是我显示帖子的循环。

 <div role="main">
<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
<div <?php post_class(); ?>>
    <article <?php post_class(); ?>>
    <header class="post-header">
     <a class="post-header" href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></header>
     <time class="post-date"><p> <?php the_time('l, j M Y')?></p></time>
    <p class="post-content"><?php echo get_the_content(); ?></p>
    <!-- put post class tags in -->
    <div class="tags-container">
    <?php $tags = get_the_tags();
    if( $tags ) : ?>
      <?php foreach( $tags as $tag ) { ?>
       <span class="tags <?php echo $tag->slug; ?>"><i class="icon icon-tag"></i><a href="<?php echo get_tag_link($tag->term_id); ?>"><?php echo $tag->name; ?></a></span>
      <?php } ?>
    <?php endif; ?>
    </div>      
    </article>
</div>
<?php endwhile; ?>
<?php endif; ?>
4

2 回答 2

4

替换<?php echo get_the_content(); ?><?php the_content(); ?>

我相信get_the_content()从数据库返回原始内容,并且不会通过应用于the_content()诸如wpautop和的正常过滤器运行它do_shortcode(尽管WP Codex 条目对此尚不清楚)。

除非您有特定的使用理由get_the_content()(例如将其传递给函数或过滤器),否则您应该使用the_content()自动回显内容并通过 WP 的默认内容过滤器运行它。

如果这不能解决您的问题,很可能是插件或自定义主题功能阻止了短代码被解析。

编辑:验证get_the_content()返回未过滤的帖子内容。奇怪的是,这并没有在 get_the_content() 函数参考中直接说明,而是在 the_content() 的函数参考中(替代用法部分)。

于 2013-09-12T15:42:00.030 回答
0

如果您自定义呈现内容,也会发生这种情况。再次,不使用该the_content()功能。

如果您不能或不想使用,您可以随时使用该功能the_content()清洗输出的内容。strip_shortcodes()像这样:

$content = $article->post_content;
$content = strip_shortcodes($content);
于 2018-11-21T09:51:54.620 回答