首页 > 其它 > 解决wordpress分类排序问题

解决wordpress分类排序问题

2009年04月26号
查看评论 发表评论 562次浏览

.首先得往wordpress分类表里加入排序字段displayorder(类型为int).

经研究,此表为wp_terms.加完后,就给你需要排序的分类依次排序,结果如下:

2.打开wp-includes目录下taxonomy.php文件,由于wordpress的搜索逻辑默认没有对新加入的字段支持,得进行修改.

找到如下位置

  1. else if ( name == $orderby )
  2. $orderby = t.name;

大概在615行,在这个位置下加入如下代码,以获得其对displayorder排序字段的支持

  1. else if ( displayorder == $orderby )
  2. $orderby = t.displayorder;

3.在wp-content/themes目录下,找到你所用的模板目录,然后编辑sidebar.php页.这一步主要是往模板页里的分类函数加入排序方式的参数.
找到wp_list_categories函数,我的如下:

  1. <?php wp_list_categories(show_count=1&title_li=<h6>categories</h6>); ?>

修改为

  1. <?php wp_list_categories(orderby=displayorder&show_count=1&title_li=<h6>categories</h6>); ?>

done.

类别其它 标签
  1. guolb
    发表于 2009年04月26号 19时44分15秒 | 1楼

    可以让displayorder这字段做索引

  2. Cheap PUMA Shoes
    发表于 2010年06月14号 14时06分18秒 | 2楼

    I agree with the suggestions in the article.

  3. puma sneakers
    发表于 2010年06月15号 04时38分39秒 | 3楼

    lol, yes, surely…

  4. mbt lami
    发表于 2010年06月18号 11时12分32秒 | 4楼

    history again.

  5. nba basketball shoes
    发表于 2010年06月24号 05时45分53秒 | 5楼

    i love it.

  6. vibram five fingers
    发表于 2010年06月30号 15时41分49秒 | 6楼

    Thankyou for sharing.

  7. Lacoste Online
    发表于 2010年07月16号 00时15分09秒 | 7楼

    Thankyou for all your inspiration and for the goodness you spread.

  8. lv tote bags
    发表于 2010年07月20号 08时39分04秒 | 8楼

    Thank you for an inspiring post which has provided me with my motivation today!

  9. authentic christian louboutin shoes
    发表于 2010年07月22号 11时34分38秒 | 9楼

    cute very cute,,, love it very relaxing have a good one