实现让wordpress首页或者分类列表只输出文章标题列表或者文章摘要

wordpress默认文章摘要方式, 首先需要在博客后台选项(options)–输出(reading)设置里,把输出方式设为摘要而不是全文;

其次还需要你在编辑发表每一篇日志时,光标停留在截取处,然后点击编辑器上一个叫做”split post with more tag” 的按钮(快捷方式是Alt+t )。

本文介绍一个一劳永逸的方法来实现让wordpress首页或者分类列表只输出文章标题列表或者文章摘要。

一、在wordpress主题中的的index.php文件中找到显示文章全文的函数:

<?php the_content(); ?>

则在一般的主题中替换如下代码可以全文显示文章内容 。

<div class=”entry”>

<?php the_content(’Read the rest of this entry ?’); ?>

</div>

二 在wordpress 中显示文章摘要的函数是:

<?php the_excerpt(); ?>

使用以下代码替换主题中显示文章的代码即可只显示文章摘要,而不是全文输出

代码1:

<div class=”entry”>

<?php the_excerpt(); ?>

<br>

<a href=”<?php the_permalink() ?>” rel=”bookmark” title=”进入文章<?php the_title();?>”>阅读全文”<?php the_title(); ?>”全文</a>

</div>

代码2:

<div class=”entry”>

<?php if(is_category() || is_archive() || is_home() ) {

the_excerpt();

} else {

the_content(’Read the rest of this entry ?’);

} ?>

<div class=”details”><div class=”inside”>

<?php comments_popup_link(’No Comments’,’1 Comment’,’% Comments’); ?> so far | <a href=”<?php

the_permalink() ?>”>阅读全文?</a></div></div>

</div>

三、在wordpress主页或者分类列表页只显示文章的标题列表:

即删除中间的 <?php the_excerpt(); ?> 或者 <?php the_excerpt(); ?> 函数即可。如杰趣网志本站显示文章的代码是:

<div class=”entry”>

</div>

声明: 本站遵循 知识共享署名-非商业协议CC2.5 共享协议. 转载请注明转自 杰趣网志
保存本页为PDF文档

没有评论 您有什么意见?

欢迎您在本站发表您的意见或见解!求提高!