Wordpress 文章/页面标题数字排序 [英] Wordpress Post/Page Title Numeric Sort

查看:35
本文介绍了Wordpress 文章/页面标题数字排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法按标题对新的 Wordpress 帖子查询进行排序,但按数字而不是按字母顺序排序?

Is there any possible way to sort a new Wordpress post query by the title, but numerically instead of alphabetically?

我有一些标题按字母顺序有很多相同的名字,然后有一些后缀,所以当然例如 Wordpress 将 title12 放在 title1 之前.由于每个类别都有几十个这样的标题要排序,让客户使用 Wordpress 的排序顺序不是一个可行的选择.

I have some titles that have a lot of the same name alphabetically, then have a number afterwords, so of course for example Wordpress is putting title12 ahead of title1. Since each category has a few dozen titles like this to sort, getting the client to use Wordpress' sort order isn't a viable option.

有什么想法吗?我可以使用默认的 Wordpress 功能找到的只是按数字对自定义字段进行排序,而不是标题.

Any thoughts? All I could find with default Wordpress functionality is sorting custom fields numerically, but not titles.

推荐答案

您只需要使用任一查询帖子修改查询:

You simply just need to modify the query using either query posts:

query_posts('orderby=title&order=ASC');

或者使用 WP_Query 创建一个全新的查询:

Or create a whole new query using WP_Query:

$query = new WP_Query( array ( 'orderby' => 'title', 'order' => 'ASC' ) );

Wordpress 计算出顺序,然后进行字母排序,然后是数字排序,类似于我相信的 php func natsort.

Wordpress figures out the ordering and does alpha then numeric sorting similar to the php func natsort I believe.

这篇关于Wordpress 文章/页面标题数字排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆