【问题标题】:Wordpress ignores excerptWordpress 忽略摘录
【发布时间】:2014-03-17 09:26:11
【问题描述】:

使用下面的内容,我可以将列表和帖子中的文本填充到 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;?>

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    如果您只收到一条回复,&lt;!--more--&gt; 将被忽略,请参阅the_excerpt() vs. the_content()

    有时,只使用the_content() 更有意义 函数将根据是否显示来决定显示什么 使用了&lt;!--more--&gt; 快速标签。 &lt;!--more--&gt; 快速标签拆分帖子 分成两部分;只有标签之前的内容应该显示在 清单。请记住,&lt;!--more--&gt; 在显示时(当然)会被忽略 一个帖子。

    尝试使用&lt;?php the_excerpt(); ?&gt;

    更新:
    就像我在 cmets 中所说的那样,Donald 得到了WordPress Support 的帮助,解决方案似乎是像WordPress Reference 一样覆盖全局$more

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

    应该这样做。

    【讨论】:

    • 我有 2 个帖子,the_content 和 excerpt 都忽略了 &lt;!--more--&gt; 标签
    • 嗯,您可以尝试在您的 while 循环下方添加 &lt;?php global $more; $more = 0; ?&gt; 吗?你用什么wordpress版本? showposts=2似乎早已不复存在。 (但似乎不是这里的问题;))
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2016-07-19
      • 1970-01-01
      • 2014-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多