• wordpress文章显示同一分类下的上一篇下一篇


    我们在用wordpress开发网站的时候会在文章页中引入上一篇下一篇,但是发现新闻页的上下文章有可能是产品分类的post,这个就不太合理,如何显示同一分类下的上一篇下一篇文章呢?随ytkah一起来看看

      我们知道普通的调用上下篇文章的代码是

    1
    2
    <div class="prev"><?php previous_post_link('« %link') ?></div>
    <div class="next"><?php next_post_link('%link »') ?></div>

      我们进行改造一下

    1
    2
    <div class="prev"><?php previous_post_link('« %link' ,' %title' , true) ?></div>
    <div class="next"><?php next_post_link('%link »','%title' , true) ?></div>

      函数用法说明:

    1
    2
    3
    4
    //上一页
    <?php next_post_link('format''link''in_same_cat''excluded_categories'); ?>
    //下一页
    <?php next_post_link('format''link''in_same_cat''excluded_categories'); ?>

      

    参数说明:

    format

    (字符串)链接的格式字符串。用该参数控制链接前后内容。字符串中的’%link’会被声明为’link’的内容(见下一个参数)取代。’Go to %link’ 将生成”Go to <a href=…” ,在其中加上相应的HTML标签,生成最终结果。默认值为 ‘%link »’。

    link

    (字符串)所显示的链接文本。默认为上一篇文章的标题(’%title’)。

    in_same_cat

    (布尔型)指明上一篇文章是否与当前文章在同一分类目录中。如果该参数值为TRUE,只显示当前文章所属分类目录下的文章。有效值包括:

    TRUE
    FALSE(默认值)
    excluded_categories

    (字符串)上一篇文章所不属于的分类目录的数值型ID。用and分隔多个分类ID,如’1 and 5 and 15’。无默认值。

    参考资料http://www.shouce.ren/post/view/id/3682

  • 相关阅读:
    Speex for Android
    反射(高大上)、类的内置方法
    hashlib摘要算法模块,logging日志,configparser配置文件模块
    抽象类,接口类,封装,property,classmetod,statimethod
    面对对象三大特征:继承 多态(鸭子类型)(面试题)
    面向对象命名空间及组合(面试题)
    初始面向对象
    模块与包
    常用模块
    列表表达式,生成器表达式,
  • 原文地址:https://www.cnblogs.com/Xuman0927/p/12716403.html
Copyright © 2020-2023  润新知