Wordpress忽略了摘录

时间:2014-03-17 09:26:12

标签: php wordpress

使用下面我能够将列表和帖子中的文本填充到Wordpress中的补充工具栏中。

我已将<!--more-->标记放入我的帖子中,但使用以下脚本似乎会被忽略。

有人可以协助吗

Wordpress中的PHP

<?php $the_query = new WP_Query( 'showposts=2' ); ?>
    <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
    <li>
        <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
        <p><?php the_content('<span class="readmore strong">'.__('Read more').'</span>'); ?></p>
    </li>
    <?php endwhile;?>

2 个答案:

答案 0 :(得分:1)

如果您只收到一篇帖子,<!--more-->将被忽略,请参阅the_excerpt() vs. the_content()

  

有时,仅使用the_content()更有意义   将根据是否决定显示什么的功能   使用<!--more--> quicktag。 <!--more--> quicktag会分割帖子   分为两部分;只应显示标签前的内容   清单。请记住,<!--more-->在显示时(当然)会被忽略   一个帖子。

尝试使用<?php the_excerpt(); ?>

<强>更新
就像我在评论中说的那样Donald得到了WordPress Support的帮助,解决方案似乎是覆盖全球$more,如WordPress Reference

<?php global $more; $more = 0; ?>

在这个问题的背景下:

<?php $the_query = new WP_Query( 'showposts=2' ); ?>
    <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
    <?php global $more; $more = 0; ?>
    <li>
        <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
        <p><?php the_content('<span class="readmore strong">'.__('Read more').'</span>'); ?></p>
    </li>
    <?php endwhile;?>

应该这样做。

答案 1 :(得分:0)

Answer from Wordpress Support

<强>的functions.php

function force_more() {
    global $more;
    $more = 0;
}

<强>的sidebar.php

<?php
  force_more();
  query_posts('category_name=mycategory&showposts=5');
  while (have_posts()) : the_post();
?>
相关问题