Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom post type with pagenavigation not working
    primarykey
    data
    text
    <p>I have been struggling all night to make this work, but it seems that I can't find the problem. I'm using Bootstrap to make a new theme, and along with it, I have a small piece of code for custom page navigation, and it seems to work fine with basic WordPess post list.</p> <p>But I have added a new custom post type called gallery, and I can't find a solution on how to list all the posts in the gallery custom post type and make pagination work. So far, I have made a new file called archive-galleries.php, and it lists all the posts with the gallery custom post type, but it won't go to the second page. I get the error <code>404 not found</code>.</p> <p>Here is the code of archive-galleries.php page</p> <pre><code>&lt;?php get_header(); ?&gt; &lt;?php get_sidebar('top'); ?&gt; &lt;div class="row"&gt; &lt;div class="span8"&gt; &lt;?php the_post(); ?&gt; &lt;h3 class="text-error"&gt;&lt;?php _e('Latest image galleries', 'vt-translate'); ?&gt;&lt;/h3&gt; &lt;?php $count = 0; $paged = intval(get_query_var('paged')); $paged = ($paged) ? $paged : 1; $query_arguments = array( 'post_type' =&gt; 'galleries', 'posts_per_page' =&gt; 4, 'paged' =&gt; $paged, ); // Query posts query_posts( $query_arguments ); while ( have_posts() ) : the_post(); $open = !($count%4) ? '&lt;div class="row"&gt;' : ''; $close = !($count%4) &amp;&amp; $count ? '&lt;/div&gt;' : ''; echo $close.$open; ?&gt; &lt;div class="span2"&gt; &lt;a href="&lt;?php the_permalink() ?&gt;"&gt; &lt;img class="thumb" data-src="holder.js/160x250" alt="&lt;?php the_title(); ?&gt;" src="&lt;?php bloginfo('template_url'); ?&gt;/inc/timthumb.php?src=&lt;?php echo get_post_meta($post-&gt;ID, 'thumb', true); ?&gt;&amp;h=250&amp;w=160&amp;zc=1" /&gt; &lt;/a&gt; &lt;div class="clearfix"&gt;&lt;/div&gt; &lt;h6&gt; &lt;a href="&lt;?php the_permalink() ?&gt;"&gt;&lt;?php trim_title(); ?&gt;&lt;/a&gt; &lt;/h6&gt; &lt;/div&gt; &lt;?php $count++; endwhile; echo $count ? '&lt;/div&gt;' : ''; ?&gt; &lt;/div&gt; &lt;div class="span4"&gt; &lt;?php get_sidebar('pageright'); ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="pagination pagination-centered"&gt; &lt;?php page_navi(); ?&gt; &lt;/div&gt;&lt;!-- #nav-below --&gt; &lt;?php get_sidebar('belownavigation'); ?&gt; &lt;?php get_footer(); ?&gt; </code></pre> <p>And here is the custom code I used for pagination, located in the functions.php file:</p> <pre><code>//Wordpress page navigation with numbers function page_navi($before = '', $after = '') { global $wpdb, $wp_query; $request = $wp_query-&gt;request; $posts_per_page = intval(get_query_var('posts_per_page')); $paged = intval(get_query_var('paged')); $numposts = $wp_query-&gt;found_posts; $max_page = $wp_query-&gt;max_num_pages; if ( $numposts &lt;= $posts_per_page ) { return; } if(empty($paged) || $paged == 0) { $paged = 1; } $pages_to_show = 7; $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 &lt;= 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 &gt; $max_page) { $start_page = $max_page - $pages_to_show_minus_1; $end_page = $max_page; } if($start_page &lt;= 0) { $start_page = 1; } echo $before.'&lt;ul&gt;'.""; if ($paged &gt; 1) { echo '&lt;li class="prev"&gt;&lt;a href="'.get_pagenum_link().'" title="First"&gt;'.__('&amp;laquo;','vt-translate').'&lt;/a&gt;&lt;/li&gt;'; } $prevposts = get_previous_posts_link('&amp;laquo; Previous'); if($prevposts) { echo '&lt;li&gt;' . $prevposts . '&lt;/li&gt;'; } else { echo '&lt;li class="active"&gt;&lt;a href="#"&gt;&amp;laquo; Previous&lt;/a&gt;&lt;/li&gt;'; } for($i = $start_page; $i &lt;= $end_page; $i++) { if($i == $paged) { echo '&lt;li class="active"&gt;&lt;a href="#"&gt;'.$i.'&lt;/a&gt;&lt;/li&gt;'; } else { echo '&lt;li&gt;&lt;a href="'.get_pagenum_link($i).'"&gt;'.$i.'&lt;/a&gt;&lt;/li&gt;'; } } echo '&lt;li class=""&gt;'; next_posts_link('Next &amp;raquo;'); echo '&lt;/li&gt;'; if ($end_page &lt; $max_page) { echo '&lt;li class="next"&gt;&lt;a href="'.get_pagenum_link($max_page).'" title="Last"&gt;'.__('&amp;raquo;','vt-translate').'&lt;/a&gt;&lt;/li&gt;'; } echo '&lt;/ul&gt;'.$after.""; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload