大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
关于调用某一指定分类的方法,可以参考我在这个问题下的回复:
创新互联公司专注于企业网络营销推广、网站重做改版、马关网站定制设计、自适应品牌网站建设、H5网站设计、商城系统网站开发、集团公司官网建设、外贸营销网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为马关等各大城市提供网站开发制作服务。
网页链接
随机文章的获取,其实只要在查询时添加排序方式就可以,如下:
'orderby' = 'rand'
完整代码:
$query = array(
'cat' = '8',
'post_type' = 'post',
'orderby' = 'rand'
);
$posts = new WP_Query( $query );
if ( $posts-have_posts() ) {
while( $posts-have_posts() ) :
$posts-the_post();
the_content();
endwhile;
}
wp_reset_query();
有时候在登录Wordpress时报错:随机数校验失败,或者认证失败等等。其实,这是WordPress的随机数和缓存导致的问题。其实就是其中一个人把登录页面缓存了,而缓存时间已经超过12个小时。Wordpress默认随机数nonce时间在12-24小时之内就会失效。只能清空缓存才能再次正常登陆。接下来搬主题就分享一下加大WordPress的随机数nonce过期时间解决缓存过期错误问题。
针对上面的问题,要么清空登录页面的缓存,要么把WordPress随机数nonce有效时间改成48小时,网页缓存(WP Super Cache等缓存插件)时间改成24小时。
实际上,WP会为那些涉及安全问题的地方,比如ajax加载之类,会提供一个随机数,每个用户不同。而这个随机数有个有效期,默认为24小时。事实上,按照WP官方描述,这个时间上是12-24小时之间,随机失效。所以,当使用各类WordPress缓存插件缓存页面超过12小时,这个随机数就有可能失效,直接导致认证失败,登陆失败等问题。
你好,去掉 'orderby' = 'rand', 这个就可以了,这个是排序的方式 。可参考WP_Query函数的相关内容。orderby可支持的值有:
orderby (string | array) – Sort retrieved posts by parameter. Defaults to ‘date (post_date)’. One or more options can be passed.
‘none‘ – No order (available since version 2.8).
‘ID‘ – Order by post id. Note the capitalization.
‘author‘ – Order by author.
‘title‘ – Order by title.
‘name‘ – Order by post name (post slug).
‘type‘ – Order by post type (available since version 4.0).
‘date‘ – Order by date.
‘modified‘ – Order by last modified date.
‘parent‘ – Order by post/page parent id.
‘rand‘ – Random order.
‘comment_count‘ – Order by number of comments (available since version 2.9).
‘relevance‘ – Order by search terms in the following order: First, whether the entire sentence is matched. Second, if all the search terms are within the titles. Third, if any of the search terms appear in the titles. And, fourth, if the full sentence appears in the contents.
‘menu_order‘ – Order by Page Order. Used most often for pages (Order field in the Edit Page Attributes box) and for attachments (the integer fields in the Insert / Upload Media Gallery dialog), but could be used for any post type with distinct ‘menu_order‘ values (they all default to 0).
‘meta_value‘ – Note that a ‘meta_key=keyname‘ must also be present in the query. Note also that the sorting will be alphabetical which is fine for strings (i.e. words), but can be unexpected for numbers (e.g. 1, 3, 34, 4, 56, 6, etc, rather than 1, 3, 4, 6, 34, 56 as you might naturally expect). Use ‘meta_value_num‘ instead for numeric values. You may also specify ‘meta_type‘ if you want to cast the meta value as a specific type. Possible values are ‘NUMERIC’, ‘BINARY’, ‘CHAR’, ‘DATE’, ‘DATETIME’, ‘DECIMAL’, ‘SIGNED’, ‘TIME’, ‘UNSIGNED’, same as in ‘$meta_query‘. When using ‘meta_type’ you can also use ‘meta_value_*’ accordingly. For example, when using DATETIME as ‘meta_type’ you can use ‘meta_value_datetime’ to define order structure.
‘meta_value_num‘ – Order by numeric meta value (available since version 2.8). Also note that a ‘meta_key=keyname‘ must also be present in the query. This value allows for numerical sorting as noted above in ‘meta_value‘.
‘post__in‘ – Preserve post ID order given in the post__in array (available since version 3.5). Note – the value of the order parameter does not change the resulting sort order.
‘post_name__in‘ – Preserve post slug order given in the ‘post_name__in’ array (available since Version 4.6). Note – the value of the order parameter does not change the resulting sort order.
‘post_parent__in‘ -Preserve post parent order given in the ‘post_parent__in’ array (available since Version 4.6). Note – the value of the order parameter does not change the resulting sort order.