如何告诉wordpress模板是存档

时间:2013-06-12 17:44:35

标签: wordpress templates archive

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

我创建了一个名为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; ?>

有什么想法吗?我一直在四处寻找想法,并且我已经看到了许多不同的方式来制作档案,但我还没有能够将它们整合在一起以适应我的用例。

1 个答案:

答案 0 :(得分:0)

解决方案是使用此代码:

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

之后不会显示任何内容

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