Wordpress排序功能不工作



好吧,我是自定义这个函数一点,但多次尝试后,我仍然得到实现的目标,实际上这个php代码只显示最老的帖子第一,但我想在它添加一个排序函数,以便它会显示最新的帖子,我张贴在每天的基础上第一。我甚至尝试从wordpress codex中添加一些功能,但由于我不是php专家,这就是为什么这些技术上的事情对我来说太困难了。帮助我在这段代码:

<?php
$i = 0;
if ( empty($image_width) ) {
if ( $columns == 1 )
$image_width = 960;
else
$image_width = 480;
}
if ( $image_ratio && $image_width ) {
$image_height = cloudfw_match_ratio( $image_width, $image_ratio );
}
$atts[ 'show_side_date_year' ] = false;
while( $posts->have_posts() ) :
$posts->the_post();
$post_data = $this->get_post();
/** Item number */
$i++;
$item_content = '';
$item_classes = array();
$item_classes[] = 'ui--blog-item ui--animation ui--accent-gradient-hover-parent clearfix';
$item_classes[] = 'layout--' . $raw_layout;
if ( $i == $post_count )
$item_classes[] = 'last-item';
$item_content .= "<div".
cloudfw_make_class( $item_classes, true ) .
">";
$link_element = array();
$link_element[0] = "<a class="ui--blog-link" href="". $post_data['permalink'] .""";
$link_element[0] .= ">";
$link_element[1] = "</a>";
$item_content .= $this->side( $post_data, $atts );
$item_content .= "<div class="ui--blog-content-wrapper">";
$item_content .= "<div class="ui--blog-header">";
$item_content .= "<{$title_element} class="ui--blog-title">" . $link_element[0] . $post_data['title'] . $link_element[1] . "</{$title_element}>";
$metas = $this->get_blog_metas( $metas_primary, $post_data );
$likes = $this->get_blog_metas( $metas_secondary, $post_data );
$item_content .= "</div>";
$excerpt = $this->get_excerpt( array('readmore' => $readmore, 'excerpt' => $show_excerpt, 'excerpt_length' => $excerpt_length, 'use_more_link' => false ) );
if ( !empty($excerpt)) {
$item_content .= "<div class="ui--blog-content">";
$item_content .= $excerpt;
$item_content .= "</div>";
}
$item_content .= "<div class="ui--blog-readmore more-link">";
$item_content .= "<a class="btn btn-small ". cloudfw_make_button_style( cloudfw_get_option( 'blog_template_mini', 'button_color', 'btn-secondary muted' ), true ) . "" href="". $post_data['permalink'] .""";
$item_content .= ">";
$item_content .= $readmore;
$item_content .= "</a>";
$item_content .= "</div>";
$item_content .= "</div>";
$item_content .= "</div>";
if ( $columns > 1 ) {
$column_array = array();
$column_array['class'] = array();
$column_array['_key'] = 'blog_mini';
//$content_out .= $item_content;
$content_out .= cloudfw_UI_column( $column_array, $item_content, '1of' . $columns . ( $i % $columns == 0 ? '_last' : '' ), $i == $post_count );
} else {
$content_out .= $item_content;
}
endwhile;

尝试将下面的代码放在语句上方:while($posts->have_posts()):

$req_url = $_SERVER['REQUEST_URI'];
$page_var =1;
$post_per_page = 10;
$page_var = $_GET['page'];
if(! $page_var)
{
    preg_match("/page/(d+)+/", $req_url, $matches);
    $page_var = $matches[1];
}
$args = array('post_type'=> 'post','orderby' => 'post_date','order' => 'DESC','post_status' => 'publish', 'posts_per_page' =>$post_per_page, 'paged'=>$page_var);
$posts = new WP_Query( $args );

最新更新