我在我的網站中查詢了顯示作者帖子或類別帖子。 這是顯示的職位功能:將查詢作爲wordpress中的主要查詢
function latest_posts_mansory(){
$output = '';
$this_category = get_category(get_query_var('cat'));
$cat_id = $this_category->cat_ID;
$args = array('post_status' => 'publish');
$args['showposts'] = 12;
if (is_author()) {
$args['author'] = get_the_author_meta('ID');
} else {
$args['category'] = $cat_id;
}
$recent_posts = wp_get_recent_posts($args);
$num_posts = count($recent_posts);
$curtitle = get_category_parents(get_query_var('cat') , false , ' - ');
if (!is_author()) {
$output .= '<div class="section_title underline" id="section-title-5314721809a17" style="border-color: #dddddd;"><span class="title">'.substr($curtitle , 0, -2).'</span></div>';
} else {
$output .= '<div class="section_title underline" id="section-title-5314721809a17" style="border-color: #dddddd;"><span class="title">Προβολή Άρθρων</span></div>';
}
$output .= '<div class="post_list masonry isotope" style="display: block; position: relative; overflow: hidden; height:494px;">';
$j=0;
if ($num_posts == 0 && is_author()){
$output .='<div class="no results" style="text-align:center;position: inherit;" align="center"><h5 ALIGN="CENTER">Δεν υπάρχουν άρθρα απ\'τον συγκεκριμένο συντάκτη</h5></div>';
}elseif ($num_posts == 0){
$output .='<div class="no results" style="text-align:center;position: inherit;" align="center"><h5 ALIGN="CENTER">Δεν υπάρχουν άρθρα σε αυτήν την κατηγορία</h5></div>';
}else{
for ($i=0; $i<$num_posts; $i++){
$recent_posts_usage = $recent_posts[$i]['ID'];
$this_ID = $recent_posts[$i]['ID'];
$post_class = join(" ", get_post_class('', $this_ID));
$this_title = get_the_title ($this_ID);
$category = get_the_category ($this_ID);
$this_category = $category[0]->cat_name;
$this_thumb = get_the_post_thumbnail($this_ID, 'medium');
$this_permalink = get_permalink($this_ID);
$page_data = get_page($this_ID);
$excerpt = T2T_Toolkit::truncate_string(apply_filters('the_content', strip_tags($page_data->post_content)), 200);
$output .= '<div class="callout_box with_post one_fourth isotope-item';
if($j==3){
$output .= ' column_last';
$j=0;
} else {
$j++;
}
$output .= '" style="position: absolute; left: 0px; top: 0px; -webkit-transform: translate3d(476px, 0px, 0px);">';
$output .= '<article id="post-'.$this_ID.'" class="'.$post_class.'">';
$output .= ' <a href="'.$this_permalink.'"> '.$this_thumb.' </a>';
$output .= '<div class="callout_box_content">';
$output .= '<h3> <a href="'.$this_permalink.'">'.$this_title.' </a></h3>';
$output .= $excerpt;
$output .='</div>';
$output .='</div>';
$output .='</article>';
}
}
$output .='</div>';
return $output;
}
add_shortcode('show_latest_posts_mansory', 'latest_posts_mansory');
的問題是,這一功能始終只顯示10個最新的帖子不管什麼閱讀設置是,甚至如果我在函數中使用這個
function limit_change_posts_archive($query){
$query->set('posts_per_page', 12);
return;
}
add_filter('pre_get_posts', 'limit_change_posts_archive', 1);
那麼,我做錯了什麼?我應該改變這個功能,以便像其頁面的主要查詢一樣工作嗎?也分頁不工作或者
退房'WP_Query' http://codex.wordpress.org/Class_Reference/WP_Query – henrywright
感謝,現在一切的偉大工程 – CDrosos