WP_Query, Pagination, static & URL problems
-
First of all, hello!
So I spent all day trying to fix this and cannot… and it gets more confusing because I am not even sure what the issue is (after finding an undesirable solution).
Problem:
I am using a theme that I downloaded, and to easily get the desired home page I have to use their custom page template as a static home page. After some modifying and testing, I realized that there was no pagination on the static home page. The original also does not contain any pagination, so I did not mess any of their stuff up… I don’t think!My problem is that I have successfully added pagination, but it fails to link properly. When I click on the various pagination links I tried, it just refreshes the page and shows the same posts. But, there is more! I can get to the other pages containing older posts if I manually type the url https://www.jovialjoystick.com/?paged=2), so I know the pages exist. I just cannot get my pagination to correctly link and when I hover over the pagination, my browser tells me it links to https://www.jovialjoystick.com/page/2/ which DOESN’T exist/work. So that makes me wonder if it is just some url output error that I hope is easily fixed? The undesirable solution is to switch WordPress’ Permalink settings to default, and then the pagination links work, but I do not want that url/permalink structure.
Here is my page’s template code, which the theme developers made (I only removed 2 other loops and added the sidebar) :
<?php $do_not_duplicate = array(); get_header(); // Loads the header.php template. ?> <!-- Begin featured area. ---> <?php $sticky = get_option( 'sticky_posts' ); rsort( $sticky ); $loop = new WP_Query( array( 'post__in' => array_slice( $sticky, 0, 5 ), 'posts_per_page' => 5, 'tax_query' => array( array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array( 'post-format-aside', 'post-format-audio', 'post-format-chat', 'post-format-link', 'post-format-quote', 'post-format-status', 'post-format-video' ), 'operator' => 'NOT IN' ) ) ) ); ?> <?php if ( $loop->have_posts() ) : ?> <div class="flexslider"> <div class="slides"> <?php while ( $loop->have_posts() ) : $loop->the_post(); $do_not_duplicate[] = get_the_ID(); ?> <figure class="slide"> <?php get_the_image( array( 'meta_key' => true, 'size' => 'unique-slider' ) ); ?> <figcaption class="slide-caption"> <?php the_title( '<h2 class="entry-title"><a href="' . get_permalink() . '">', '</a></h2>' ); ?> <div class="entry-summary"> <?php the_excerpt(); ?> </div><!-- .entry-summary --> </figcaption><!-- .slide-caption --> </figure><!-- .slide --> <?php endwhile; ?> </div><!-- .slides --> </div><!-- .flexslider --> <?php endif; ?> <!-- End featured area. --> <div id="content" class="hfeed"> <!-- Begin excerpts area. --> <?php if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } elseif ( get_query_var('page') ) { $paged = get_query_var('page'); } else { $paged = 1; } $loop = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 3, 'paged' => $paged, 'tax_query' => array( array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array( 'post-format-aside', 'post-format-audio', 'post-format-chat', 'post-format-gallery', 'post-format-image', 'post-format-link', 'post-format-quote', 'post-format-status', 'post-format-video' ), 'operator' => 'NOT IN' ) ), 'post__not_in' => $do_not_duplicate ) ); ?> <?php if ( $loop->have_posts() ) : ?> <div class="content-secondary"> <?php while ( $loop->have_posts() ) : $loop->the_post(); $do_not_duplicate[] = get_the_ID(); ?> <article id="post-<?php the_ID(); ?>" class="<?php hybrid_entry_class(); ?>"> <?php if ( current_theme_supports( 'get-the-image' ) ) get_the_image( array( 'meta_key' => 'Thumbnail', 'size' => 'thumbnail' ) ); ?> <header class="entry-header"> <?php echo apply_atomic_shortcode( 'entry_title', '[entry-title tag="h2"]' ); ?> <?php echo apply_atomic_shortcode( 'entry_byline', '<div class="entry-byline">' . __( 'Published on [entry-published] [entry-edit-link before=" | "]', 'unique' ) . '</div>' ); ?> </header><!-- .entry-header --> <div class="entry-summary"> <?php the_excerpt(); ?> </div><!-- .entry-summary --> </article><!-- .hentry --> <?php endwhile; ?> </div><!-- .content-secondary --> <?php global $wp_query; $big = 999999999; // need an unlikely integer echo paginate_links( array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('page') ), 'total' => $loop->max_num_pages ) ); ?> <?php endif; ?> <?php wp_reset_query(); ?> </div><!-- #content --> <?php get_footer(); // Loads the footer.php template. ?>
I specifically added:
<?php if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } elseif ( get_query_var('page') ) { $paged = get_query_var('page'); } else { $paged = 1; }
And this (which I think can solve my url structure in the format, but I am not sure how to do it.)
<?php global $wp_query; $big = 999999999; // need an unlikely integer echo paginate_links( array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('page') ), 'total' => $loop->max_num_pages ) ); ?>
I researched for a long time and just could not get it to work because I am not sure if my urls, code and/or structure is the problem.
Also, I am not using the custom page template how it came. The original contained 2 MORE loops to display gallery archives, so maybe there is a better way of doing what I want? Which is: the sticky post controlled slider with the latest blog posts under it.
I did try to modify the index.php file, so I could just use the main loop… but I could not get the slider to show up properly, which I figured required a lot of theme modifying and dissecting, which I will attempt if I must.
- The topic ‘WP_Query, Pagination, static & URL problems’ is closed to new replies.