wordpress增加同类目上一篇下一篇的功能

罗帆 草根站长 2017-06-15 1219 0

增加上一篇 下一篇这些代码,修改这个文件


單篇文章(single.php)





增加下面代码


<?php

    $categories = get_the_category();

    $categoryIDS = array();

    foreach ($categories as $category) {

        array_push($categoryIDS, $category->term_id);

    }

    $categoryIDS = implode(",", $categoryIDS);

?>

<?php if (get_previous_post($categoryIDS)) { previous_post_link('上壹篇: %link','%title',true);} else { echo "沒有了,已經是最後文章";} ?>

<br>

<?php if (get_next_post($categoryIDS)) { next_post_link('下壹篇: %link','%title',true);} else { echo "沒有了,已經是最新文章";} ?>




另外:在WordPress首页和目录页显示摘要的方法


 在WordPress系统中,默认的首页和目录页使用的书全文输出,这对于文章内容较长的博客来说很不方面,下面我介绍一个方法,可以简单的实现在WordPress首页和目录页显示摘要而非全文。


  首先找到wp-content/themes下你使用的模板目录,查找目录中的文件,如果有home.php则修改home.php,没有的话就修改index.php,找到<?php the_content(); ?>这一行,将其修改为以下代码:


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

     the_excerpt();

 } else {

     the_content('Read the rest of this entry &raquo;');

 } ?>

 <div class="details"><div class="inside"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?> so far | <a href="<?php the_permalink() ?>">Read On &raquo;</a></div></div>


  这时,你的WordPress首页和分类就显示为摘要信息而不是全文信息了。


  这段代码可以在你的首页、存档页、目录页使用摘要输出,使用摘要输出后,整个WordPress的重复内容就少多了,很利于搜索引擎优化。


评论