Wordpress标题破碎

时间:2013-09-12 15:32:22

标签: php html css wordpress

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

Problem

这是我显示帖子的循环。

 <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; ?>

2 个答案:

答案 0 :(得分:4)

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

我相信get_the_content()会返回来自数据库的原始内容,并且不会通过应用于the_content()的常规过滤器(例如wpautopdo_shortcode运行它(尽管WP Codex entry对此并不清楚。)

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

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

编辑:已验证get_the_content()返回未经过滤的帖子内容。奇怪的是,这不是在get_the_content()函数引用中直接声明,而是在function reference for the_content()(备用内容部分)中。

答案 1 :(得分:0)

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

如果您不愿意使用the_content(),则始终可以使用strip_shortcodes()函数来清洗输出的内容。像这样:

$content = $article->post_content;
$content = strip_shortcodes($content);
相关问题