【问题标题】:show last 5 posts that have <!--more-->显示最后 5 个具有 <!--more--> 的帖子
【发布时间】:2009-10-17 15:50:27
【问题描述】:

我想在 wordpress 页面中显示最后 5 个帖子,但是当我使用此代码时,它将返回整个帖子正文,而我的帖子中有 &lt;!--more--&gt;,我想显示到这一部分。 这是我正在使用的代码:

   <div>
        <ul>
            <? query_posts('showposts=5'); ?>
            <?php while (have_posts()): the_post(); ?>
            <li>
                <a href="<?php the_permalink() ?>"><?php the_contenet(); ?></a>
            </li>
            <?php endwhile; ?>
        </ul>
    </div>

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    将其从 the_content 更改为 the_excerpt 然后它会显示预告片而不是完整内容...

    【讨论】:

    • 我做到了,但是直到我放 命令的地方它才会显示,它会剪切到任何它想要的地方!
    【解决方案2】:

    我不知道你想要什么;您想要最近五篇文章的列表,还是打印最近五篇文章的内容?

    有些事情:你拼错了the_content。而且你有一个不需要的结束标签:&lt;/a&gt; 如果你想要一个帖子列表,the_content 不是你想要的,无论如何:你想要the_title

    而且,如果您在主 wordpress 循环中使用它,它需要是一个新查询,因此它不会与循环冲突:

    &lt;?php $my_query = new WP_Query('showposts=5'); ?&gt;&lt;?php while ($my_query-&gt;have_posts()) : $my_query-&gt;the_post(); ?&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" title="&lt;?php the_title(); ?&gt;"&gt;&lt;?php the_content(); ?&gt;&lt;?php endwhile; ?&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 2020-10-11
      • 1970-01-01
      • 2020-04-14
      • 2011-09-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多