WordPress on the homepage using query_posts () page 404?

Source: Internet
Author: User
In the development of the younger brother encountered a problem, the idea is probably this:

    • Set up four article types ('post','detail','jingyan','haitao) , equivalent to "article" peers in the background.

    • On the home page, pick up all of the four article types, as follows:


  
    $notcat,        'post__not_in' => $sticky,        'post_type'=>array( 'post','detail','jingyan','haitao'),        'posts_per_page' => 15,        'paged' => $paged    );    query_posts( $args );?>
  
   
  
   ...
  
   
    • Functions.php added these:


  
   set('post_type',$post_type);        $query->set('posts_per_page', 15);    return $query;    }}

Here's the problem: after outputting content in such a way, pagination is displayed only in the number of articles . For example, there are 60 articles under "post", "detail", "jingyan", "haitao" 10 articles. According to the idea should be divided (60+10*3)/15 = 6 pages. However, the actual situation is turned to 60/15 = 4 page end, 5th, 6 pages are displayed 404.

Copy someone else's pagenavi() :


  Request        $posts _per_page = intval (Get_query_var (' posts_per_page '));        $paged = Intval (Get_query_var (' paged '));        $numposts = $WP _query->found_posts;        $max _page = $wp _query->max_num_pages;        if (Empty ($paged) | | $paged = = 0) {$paged = 1;        } $pages _to_show = intval ($pagenavi _options[' num_pages ');        $pages _to_show = intval (4);        $pages _to_show_minus_1 = $pages _to_show-1;        $half _page_start = Floor ($pages _to_show_minus_1/2);        $half _page_end = ceil ($pages _to_show_minus_1/2);        $start _page = $paged-$half _page_start;        if ($start _page <= 0) {$start _page = 1;        } $end _page = $paged + $half _page_end;        if ($end _page-$start _page)! = $pages _to_show_minus_1) {$end _page = $start _page + $pages _to_show_minus_1;            } if ($end _page > $max _page) {$start _page = $max _page-$pages _to_show_minus_1;        $end _page = $max _page;        }if ($start _page <= 0) {$start _page = 1; if ($max _page > 1 | | intval ($pagenavi _options[' always_show ') = = 1) {$pages _text = str_replace ("%cu            Rrent_page% ", number_format_i18n ($paged)," total%total_pages% pages ");            $pages _text = Str_replace ("%total_pages%", number_format_i18n ($max _page), $pages _text); echo $before. '. '            \ n "; if (!empty ($pages _text)) {echo ''. $pages _text. ''; if ($start _page >= 2 && $pages _to_show < $max _page) {$first _                Page_text = Str_replace ("%total_pages%", number_format_i18n ($max _page), "«First page");                echo ". $first _page_text."; Echo '...';            } previous_posts_link ("«");                    for ($i = $start _page; $i <= $end _page; $i + +) {if ($i = = $paged) {                    $current _page_text = Str_replace ("%page_number%", number_format_i18n ($i), "%page_number%"); Echo ''. $current _page_text. '';                    } else {$page _text = str_replace ("%page_number%", number_format_i18n ($i), "%page_number%");                echo ". $page _text.";            }} next_posts_link ("»", $max _page); if ($end _page < $max _page) {echo ''." ...".'';                $last _page_text = Str_replace ("%total_pages%", number_format_i18n ($max _page), "last»");            Echo ' Last» '; } Echo '. $after. "        \ n "; }}}?>

Reply content:

In the development of the younger brother encountered a problem, the idea is probably this:

    • Set up four article types ('post','detail','jingyan','haitao) , equivalent to "article" peers in the background.

    • On the home page, pick up all of the four article types, as follows:


  
    $notcat,        'post__not_in' => $sticky,        'post_type'=>array( 'post','detail','jingyan','haitao'),        'posts_per_page' => 15,        'paged' => $paged    );    query_posts( $args );?>
  
   
  
   ...
  
   
    • Functions.php added these:


  
   set('post_type',$post_type);        $query->set('posts_per_page', 15);    return $query;    }}

Here's the problem: after outputting content in such a way, pagination is displayed only in the number of articles . For example, there are 60 articles under "post", "detail", "jingyan", "haitao" 10 articles. According to the idea should be divided (60+10*3)/15 = 6 pages. However, the actual situation is turned to 60/15 = 4 page end, 5th, 6 pages are displayed 404.

Copy someone else's pagenavi() :


  Request        $posts _per_page = intval (Get_query_var (' posts_per_page '));        $paged = Intval (Get_query_var (' paged '));        $numposts = $WP _query->found_posts;        $max _page = $wp _query->max_num_pages;        if (Empty ($paged) | | $paged = = 0) {$paged = 1;        } $pages _to_show = intval ($pagenavi _options[' num_pages ');        $pages _to_show = intval (4);        $pages _to_show_minus_1 = $pages _to_show-1;        $half _page_start = Floor ($pages _to_show_minus_1/2);        $half _page_end = ceil ($pages _to_show_minus_1/2);        $start _page = $paged-$half _page_start;        if ($start _page <= 0) {$start _page = 1;        } $end _page = $paged + $half _page_end;        if ($end _page-$start _page)! = $pages _to_show_minus_1) {$end _page = $start _page + $pages _to_show_minus_1;            } if ($end _page > $max _page) {$start _page = $max _page-$pages _to_show_minus_1;        $end _page = $max _page;        }if ($start _page <= 0) {$start _page = 1; if ($max _page > 1 | | intval ($pagenavi _options[' always_show ') = = 1) {$pages _text = str_replace ("%cu            Rrent_page% ", number_format_i18n ($paged)," total%total_pages% pages ");            $pages _text = Str_replace ("%total_pages%", number_format_i18n ($max _page), $pages _text); echo $before. '. '            \ n "; if (!empty ($pages _text)) {echo ''. $pages _text. ''; if ($start _page >= 2 && $pages _to_show < $max _page) {$first _                Page_text = Str_replace ("%total_pages%", number_format_i18n ($max _page), "«First page");                echo ". $first _page_text."; Echo '...';            } previous_posts_link ("«");                    for ($i = $start _page; $i <= $end _page; $i + +) {if ($i = = $paged) {                    $current _page_text = Str_replace ("%page_number%", number_format_i18n ($i), "%page_number%"); Echo ''. $current _page_text. '';                    } else {$page _text = str_replace ("%page_number%", number_format_i18n ($i), "%page_number%");                echo ". $page _text.";            }} next_posts_link ("»", $max _page); if ($end _page < $max _page) {echo ''." ...".'';                $last _page_text = Str_replace ("%total_pages%", number_format_i18n ($max _page), "last»");            Echo ' Last» '; } Echo '. $after. "        \ n "; }}}?>
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.