【问题标题】:How do I tell wordpress that a template is an archive如何告诉 wordpress 模板是存档
【发布时间】:2013-06-12 17:44:34
【问题描述】:

用例是我想在页面上列出最新的帖子。每个帖子仅包含摘要和标题以及指向完整帖子的链接。

我创建了一个名为“Latest Posts”的模板,它可以正常加载。但是我希望 get_content() 以某种方式理解这个模板是一个存档模板,因此只显示摘录而不是完整的帖子。

我对所有其他列表使用以下“内容”模板,并希望在列出我的最新帖子时重复使用它,但由于它既不是搜索也不是存档,所以第一个选择被跳过,并且 the_content() 将显示整个帖子。

<?php if ( is_search() ) : // Only display Excerpts for Search ?>
<div class="entry-summary">
    <?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php else : ?>
<div class="entry-content">
    <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'bbl' ) ); ?>
    <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'bbl' ), 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<?php endif; ?>

有什么想法吗?我一直在四处寻找想法,并看到了很多不同的存档方法,但我无法将它们组合在一起以适应我的用例。

【问题讨论】:

    标签: wordpress templates archive


    【解决方案1】:

    解决方法是使用这段代码:

    global $more;    // Declare global $more (before the loop).
    ....
    $more = 0;       
    ....
    

    可以在文档中找到有关此主题的更多信息: http://codex.wordpress.org/Function_Reference/the_content#Overriding_Archive.2FSingle_Page_Behavior

    现在 the_content() 不会在 more-tag 之后显示任何内容

    它并没有真正告诉引擎这是一个存档页面,而只是模仿行为

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-16
      • 1970-01-01
      • 2019-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-04
      • 1970-01-01
      相关资源
      最近更新 更多