On the homepage of WordPress, use query_posts () to page 404?

Source: Internet
Author: User
The younger brother encountered a problem during development. The idea was probably like this: set four types of articles (& #039; post & #039;, & #039; detail & #039 ;, & #039; jingyan & #039;, & #039; haitao), equivalent to the "article" in the background. Retrieve all the content from the four types of articles on the homepage, as shown in the following code: {code ...} functions. php added... the younger brother encountered a problem during development. The idea is probably like this:

  • Set four Article types('post','detail','jingyan','haitao), Equivalent to the "article" in the background.

  • Retrieve all the content from the four types of articles on the homepage, as shown below:


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


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

Question:After the content is output in this way,Display by number of articles by PAGE. For example, there are 60 articles under "Post", 10 for "detail", "jingyan", and "haitao. According to the idea, it should be divided into (60 + 10*3)/15 = 6 pages. However, after turning to page 60/15 = 4, pages 5th and 6 show 404.

Copy others'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); $ detail = $ pages_to_show-1; $ half_page_start = floor ($ pages_to_show_mi Nus_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 )! = $ Response) {$ end_page = $ start_page + $ response;} 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 ("% CURRENT_PAGE %", number_format_i18n ($ paged), "% TOTAL_PAGES % PAGE"); $ 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 ), "«page 1"); echo ''. $ first_page_text. ''; echo '... ';} previus_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:

The younger brother encountered a problem during development. The idea is probably like this:

  • Set four Article types('post','detail','jingyan','haitao), Equivalent to the "article" in the background.

  • Retrieve all the content from the four types of articles on the homepage, as shown below:


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


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

Question:After the content is output in this way,Display by number of articles by PAGE. For example, there are 60 articles under "Post", 10 for "detail", "jingyan", and "haitao. According to the idea, it should be divided into (60 + 10*3)/15 = 6 pages. However, after turning to page 60/15 = 4, pages 5th and 6 show 404.

Copy others'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); $ detail = $ pages_to_show-1; $ half_page_start = floor ($ pages_to_show_mi Nus_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 )! = $ Response) {$ end_page = $ start_page + $ response;} 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 ("% CURRENT_PAGE %", number_format_i18n ($ paged), "% TOTAL_PAGES % PAGE"); $ 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 ), "«page 1"); echo ''. $ first_page_text. ''; echo '... ';} previus_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" ;}}?>

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.