Community Forums › Forums › Archived Forums › General Discussion › Pagination issue with a custom category template
Tagged: broken pagination, custom loop
- This topic has 10 replies, 4 voices, and was last updated 8 years, 2 months ago by vannt93.
-
AuthorPosts
-
September 13, 2016 at 8:45 am #193085studionooblyMember
So I have the following code that is the basic backbone of a customised category.php page but I can't get the pagination links to show:
remove_action ('genesis_loop', 'genesis_do_loop'); add_action( 'genesis_loop', 'custom_do_press_loop' ); function custom_do_press_loop() { $args = array( 'post_type' => 'post', 'posts_per_page' => 3, 'orderby' => 'date', 'order' => 'DSC', ); $loop = new WP_Query( $args ); if( $loop->have_posts() ): while( $loop->have_posts() ): $loop->the_post(); global $post; endwhile; endif; } genesis();
I have also tried the following but that gave me a next link that took me to a 404 page and I think it might be deprecated so not using it any more.
remove_action ('genesis_loop', 'genesis_do_loop'); add_action( 'genesis_loop', 'custom_do_press_loop' ); function custom_do_press_loop() { global $paged; global $query_args; $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => '3', 'cat' => 'category_name', 'orderby' => 'post_date', 'paged' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1 ); global $wp_query; $wp_query = new WP_Query( $args ); if ( have_posts() ) : while ( have_posts() ) : the_post(); endwhile; do_action( 'genesis_after_endwhile' ); endif; wp_reset_query(); } genesis();
In the 'Reading Settings' I have 'Posts page' set to nothing and a static front page, there isn't a default category blog page as such on the website. And my 'Permalink Settings' are "/%category%/%postname%/" "Category base" = .
This along with setting URL's to be "www.category-name/sub-category/sub-category-post" is driving me nuts. Any help on this would be most appreciated.
Thanks,
http://localhostSeptember 13, 2016 at 3:25 pm #193115Brad DaltonParticipantHi
What are you trying to do because the code you posted doesn't output anything and isn't coded correctly.
September 14, 2016 at 12:59 am #193146studionooblyMemberHi Brad,
Oh, well that's not a good start. I'm just trying to create a custom category template page for all categories. Within the loop I have my custom html that I need to be different from the standard Genesis fair.
Here is the full code that I'm using just now.
<?php /** * This is Category file. * * @package Genesis-Child-Theme * @since 1.0.0 */ /** * Genesis custom loop */ /** Replace the standard loop with our custom loop */ remove_action ('genesis_loop', 'genesis_do_loop'); // Remove the standard loop add_action( 'genesis_loop', 'custom_do_press_loop' ); // Add custom loop function custom_do_press_loop() { $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'post_type' => 'post', 'cat' => 'category_name', 'posts_per_page' => 3, 'orderby' => 'date', 'order' => 'DSC', 'paged' => $paged ); echo '<section>'; /* Overwrite $wp_query with our new query. The only reason we're doing this is so the pagination functions work, since they use $wp_query. If pagination wasn't an issue, use: https://gist.github.com/3218106 */ $loop = new WP_Query( $args ); if( $loop->have_posts() ): while( $loop->have_posts() ): $loop->the_post(); global $post; echo '<article>'; echo '<div class="entry-content grey">'; echo '<header class="entry-header block-link-entry-header">'; echo '<h2 class="entry-title block-link-entry-title">' . get_the_title() . '</h2>'; echo '</header>'; echo '<p>' . get_the_date() . '</p>'; echo '<p>' . get_the_excerpt() . '</p>'; echo '</div>'; echo '<a href="' . get_permalink() . '" class="block-link image-block-link">'; echo get_the_post_thumbnail(); echo '</a>'; echo '</article>'; endwhile; do_action( 'genesis_after_endwhile' ); echo '</section>'; wp_reset_query(); endif; } genesis();
September 14, 2016 at 9:36 pm #193177Genesis DeveloperMemberHere is the updated code http://pastebin.com/rh6j6JRF.
You used 'cat' => 'category_name',. I am not sure that it will work correctly. Parameter "cat" is accepting the category ID not cat name or cat slug
September 14, 2016 at 10:04 pm #193178Brad DaltonParticipantYou could also use genesis_custom_loop() if you wanted to maintain the default markup.
September 15, 2016 at 8:13 am #193190studionooblyMemberThanks Brad,
Still getting a 404?
So I installed the 'Debug This' plugin and checked the Query > Rewrites and got the following
Matched Rule: (.+?)/([^/]+)(?:/([0-9]+))?/?$
Matched Query: category_name=music&name=page&page=2
Query String: page=2&name=page&category_name=music&debug-this=rewritesI found this article http://meigwilym.com/fixing-the-wordpress-pagination-404-error/
and tried the following code in my functions but no joy? (edit and flushed the permalinks)
function mg_news_pagination_rewrite() { add_rewrite_rule(get_option('category_base').'/([^/]+)(?:/([0-9]+))?/?$', 'index.php?pagename='.get_option('category_base').'&paged=$matches[1]', 'top'); } add_action('init', 'mg_news_pagination_rewrite');
Really not sure what to do now?
September 15, 2016 at 9:59 am #193201Genesis DeveloperMemberSeptember 15, 2016 at 10:10 am #193203studionooblyMemberYup, tried your code too, thanks but it still retrieves to the 404 message
September 15, 2016 at 10:18 am #193204Genesis DeveloperMemberYes. It is not working. Sorry for it.
September 16, 2016 at 8:42 am #193239studionooblyMemberOK so I finally figured out what was causing the issue. I am using Custom Meta Boxes 2 and on some templates I'm using repeatable fields and if you don't use:
<?php if ( ! empty( $term ) ) : ?>
don't forget the<?php endif; ?>
at the end.Then on empty fields that are not filled in by the user you will end up with errors that can apparently reek havoc with things like pagination.
September 18, 2016 at 7:23 am #193308vannt93MemberUseful! Thanks
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.