记录生活 学习SEO优化 | 他日若遂凌云志 敢笑黄巢不丈夫
>>Home > 学习笔记 > 给WordPress加上文章目录导航

给WordPress加上文章目录导航

Tags: | | 作者:海天无影

不知道大家发现没,海天的BLOG的文章的顶端已经加上了文章目录的导航了。当然这个在很多主题里都有此项功能显示了,但给没有这个功能主题加上还是很不错的,就像现在海天用的powerV3主题。海天还是蛮喜欢加上这样一个导航的,感觉比较正式,特别是有子目录的时候,更方便访客知道页面是在什么项目下的。

此文章目录导航功能,大家见的最多的地方应该是论坛。有了这个文章导航功能,访客就可以方便地知道并访问同类的文章, 并明确文章的所属, 这样对提高用户体验和网站的PV值都很有帮助,闲来看看怎么实现的吧。

文章目录导航功能是在大牛neoease的《WordPress 的文章导航》看到的,可以给文章加上分类或是子分类的导航目录。可能有人在这里会被绕晕了,其实海天举个例子就很好理解了。

只有分类的文章目录导航(不显示子分类) : 首页 > 分类 > 文章
带子分类的文章目录导航(显示子分类) : 首页 > 分类 > 子分类 > 第二层子分类 > ... > 第 N 层子分类 > 文章

想要什么样式的大家应该都能确定下来了,海天加的是有子目录导航的,海天还是喜欢目录导航能长一点的,觉得充实好看,哈哈。现在来在你的主题中加上文章目录导航功能。

1. 不包含父级分类的文章目录导航
这里用到 the_category() 方法的默认模式, 会调用 get_the_category_list() 生成最后一层的子分类 (分类可能不只一个) 组成的 HTML 字符串并打印到页面上. 代码如下:

<a title="Go to homepage" href="<?php echo get_settings('home'); ?>/">Home</a> <!-- 首页链接 -->
 &gt; <?php the_category(', '); ?> <!-- 每个分类以逗号分隔 -->
 &gt; <?php the_title(); ?> <!-- 文章链接 -->

2. 包含父级分类的文章目录导航
我们要用的是 the_category() 方法的 multiple 模式, 而他会调用 get_the_category_list()get_category_parents() 两个方法生成一个包含所有父分类的 HTML 字符串并打印到页面上. 代码如下:

<a title="Go to homepage" href="<?php echo get_settings('home'); ?>/">Home</a> <!-- 首页链接 -->
 &gt; <?php the_category(' &gt; ', 'multiple'); ?> <!-- 每个分类以 > 分隔, 父级分类在前, 子分类在后 -->
 &gt; <?php the_title(); ?> <!-- 文章链接 -->

选择合适的代码直接加在在需要调用文章目录导航的地方就可以了。

日志信息 »

该日志于2010-04-28 12:28由 海天无影 发表在学习笔记分类下, 你可以发表评论。除了可以将这个日志以保留源地址及作者的情况下转载到你的网站或博客,还可以通过RSS 2.0订阅这个日志的所有评论。

19条评论▼点击进行评论


  1. Warning: copy(/home/wwwroot/haitian/blog/avatar/c7066dbe1db70fc3942d21503df04338.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    :lol: 纯帮顶了~


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 你又来 纯碎的顶了~


  2. Warning: copy(/home/wwwroot/haitian/blog/avatar/0f6840987df0326df65aaa142fd9245b.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    博主的将鼠标移到导航栏可以显示的~
    能不能发个代码给我
    QQ 15357118


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      移到导航栏可以显示的?
      是不是指移到导航栏链接上弹出的那个黑底的框啊?


      • Warning: copy(/home/wwwroot/haitian/blog/avatar/0f6840987df0326df65aaa142fd9245b.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
        回复

        是的~


        • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
          回复

          已加你QQ


  3. Warning: copy(/home/wwwroot/haitian/blog/avatar/84b31b3e1fd8a12b9ab4fe1b247b68e0.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    好东西,我也来帮的顶一下,嘿嘿


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      可惜你的是PJ
      要不然也能加上了~


  4. Warning: copy(/home/wwwroot/haitian/blog/avatar/c4668a51a1479f6c344c7b79636c2236.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    我博客有了,哈哈


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵是啊 有的主题是自带的~


  5. Warning: copy(/home/wwwroot/haitian/blog/avatar/a2875770e721dbc746e714f20d3f909c.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    我用的是插件来实现的这个功能,看来有时间也要再去搞一下


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 这个还有插件的啊 没注意
      呵呵 简单加几句代码就好了
      看下你插件的CSS样式,赶快换了吧


  6. Warning: copy(/home/wwwroot/haitian/blog/avatar/46c6d01621cca0643579a15968e65bb5.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    这个好,我要学习下


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      恩 你的BLOG上也能加一个哦~


  7. Warning: copy(/home/wwwroot/haitian/blog/avatar/8a696fb2b60f79867e39e7803303fc7a.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    这个代码可以从优这个导航条的皮肤上拔下来的,哈哈,比如大名鼎鼎的inove主题,哈哈。


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 我这个代码就是在inove的作者那找的 呵呵


  8. Warning: copy(/home/wwwroot/haitian/blog/avatar/6615a55e2680bcb017fd59c14c985676.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    谢兄弟分享,感觉用途不是特大。。


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 用途说过了哦
      访客就可以方便地知道并访问同类的文章, 并明确文章的所属, 这样应该对提高用户体验和网站的PV值都很有帮助。


  9. Warning: copy(/home/wwwroot/haitian/blog/avatar/c97d5ed7936e8a93bf668d771bc0eb00.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    恩 学习下,等换主题了也好用


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      你现在不是用的和我一样的power吗?
      呵呵,可以加上去啊~


  10. Warning: copy(/home/wwwroot/haitian/blog/avatar/53ac5e73cc4436c21bc5364bb95aac49.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    这个不错哦 有利于SEO


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      嗯 试试啊,还有利于提高用户体验 呵呵~


  11. Warning: copy(/home/wwwroot/haitian/blog/avatar/0dcedda7123567217b5ce259e203a209.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    不错,呵呵


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 你BLOG的主题不是没有吗
      将上去呗~


  12. Warning: copy(/home/wwwroot/haitian/blog/avatar/b016fdf3945914d394b07ba16126c486.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    wp让你折腾很久了吧


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      嘿嘿 差不多折腾好了~


  13. Warning: copy(/home/wwwroot/haitian/blog/avatar/0add08e212ec07498618635abac4850f.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    博客不错哦~~效果很好! :lol: 支持一下!


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      嘿嘿 谢谢支持~


  14. Warning: copy(/home/wwwroot/haitian/blog/avatar/b041fec6d9b41851a84ef29a4827c1d7.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    这个好,我看有的主题就自带这个,看来作者本身就改好了,呵呵


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      恩 你的主题是自带的
      现在好多主题都自带的,有这个方便,呵呵~


  15. Warning: copy(/home/wwwroot/haitian/blog/avatar/c1aee3e82432b41a3ac099efcc02b8e4.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    添加成功~~感谢哦


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      哈哈 客气 客气了
      我也是看人家高手的
      能帮到大家就好~


  16. Warning: copy(/home/wwwroot/haitian/blog/avatar/84b247d4983ca17e696bcbd042f9313f.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    添加失败。。。。正在测试中


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      怎么了 出什么问题了 你要注意我文章里代码的标点符号啊


      • Warning: copy(/home/wwwroot/haitian/blog/avatar/84b247d4983ca17e696bcbd042f9313f.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
        回复

        理解能力不是很好。

        没看懂呢、


        • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
          回复

          额 那你直接加上去呢 注意标点
          不行吗


  17. Warning: copy(/home/wwwroot/haitian/blog/avatar/e657612476777faf50d5f28627975291.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    这个风格还是挺不错的,尤其是细节上的处理很好,有时间抽空模仿一下。

icon_wink.gif icon_neutral.gif icon_mad.gif icon_twisted.gif icon_smile.gif icon_eek.gif icon_sad.gif icon_rolleyes.gif icon_razz.gif icon_redface.gif icon_surprised.gif icon_mrgreen.gif icon_lol.gif icon_idea.gif icon_biggrin.gif icon_evil.gif icon_cry.gif icon_cool.gif icon_arrow.gif icon_confused.gif icon_question.gif icon_exclaim.gif 

« 周杰伦2010新专辑主打歌《烟花易冷》《超人不会飞》 不负如来不负卿 »