Php 按邮政编号订购邮政
我在模板上有这个函数Php 按邮政编号订购邮政,php,wordpress,Php,Wordpress,我在模板上有这个函数 function wp_posts( $layout = 'blog-posts' ) { if ( have_posts() ) : $i = 1; while ( have_posts() ) : the_post(); do_action('fwp_before_post_content'); get_template_part('extend-helpers/' . $layout);
function wp_posts( $layout = 'blog-posts' ) {
if ( have_posts() ) :
$i = 1;
while ( have_posts() ) : the_post();
do_action('fwp_before_post_content');
get_template_part('extend-helpers/' . $layout);
do_action('fwp_after_post_content');
$i++;
endwhile;
else:
get_template_part('extend-helpers/content', 'none');
endif;
}
如何按所需ID对帖子进行排序?试试以下方法:
<?php
function wp_posts( $layout = 'blog-posts' ) {
global $query_string;
query_posts($query_string . '&orderby=id&order=ASC');
if ( have_posts() ) :
$i = 1;
while ( have_posts() ) : the_post();
do_action('fwp_before_post_content');
get_template_part('extend-helpers/' . $layout);
do_action('fwp_after_post_content');
$i++;
endwhile;
else:
get_template_part('extend-helpers/content', 'none');
endif;
}
?>
下面的代码将按降序显示自定义帖子类型“推荐”orderby ID
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query(); $wp_query->query('post_type=testimonial&post_status=publish&showposts=4&orderby=ID&order=DESC' . '&paged='.$paged);
while ($wp_query->have_posts()) :
$wp_query->the_post();
endwhile;
想法是按准确的id排序…也许使用数组?或者我该怎么做?所有的帖子都应该使用这个函数进行排序。Nvm。你的一个例子:query_posts($query_string.&p=1,2,3');其中1,2,3-ids“p”参数采用单个post ID作为整数:(