WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Not working custom navigation (2 posts)

  1. justinos
    Member
    Posted 1 year ago #

    I can't get this custom navigation to work. It just doesn't show up. I hope someone can help me.

    Thank you!

    Functions.php:

    function kriesi_pagination($pages = '', $range = 4)
    {
         $showitems = ($range * 2)+1;  
    
         global $paged;
         if(empty($paged)) $paged = 1;
    
         if($pages == '')
         {
             global $wp_query;
             $pages = $wp_query->max_num_pages;
             if(!$pages)
             {
                 $pages = 1;
             }
         }   
    
         if(1 != $pages)
         {
             echo "<H4 align='center' style='margin-bottom: 0px;'>Page navigation:</H4>";
    		 echo "<div class='pagination' align='center'>";
             if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>«</a>";
             if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>‹</a>";
    
             for ($i=1; $i <= $pages; $i++)
             {
                 if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
                 {
                     echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
                 }
             }
    
             if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'>›</a>";
             if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>»</a>";
             echo "</div>\n";
         }
    }

    page.php:

    <?php $count = 1; ?>
    
        <?php
    		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    		$wp_query = new WP_Query( array( 'paged' => $paged, 'post_type' => 'ridesforsale', 'order' => 'DESC', 'orderby' => 'date', 'posts_per_page' => 2) );
    	?>
        <?php while (  $wp_query->have_posts() ) :  $wp_query->the_post(); ?>
        <?php $imageBrandbox = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?> 
    
        ...some code here...
    
        <?php $count = $count+1; ?>
          <?php
    	  	endwhile;
    		wp_reset_query();
    	  ?> 
    
        <div class="clearboth"></div>
    
    	<?php kriesi_pagination($wp_query->max_num_pages); ?>
  2. justinos
    Member
    Posted 1 year ago #

    I found the solution with a little help from someone else. Its quiet easy, but very hard to find on the internet.

    I just had to change wp_query in page.php to something else. Apparently WordPress gets confused with normal wp_query tag.

    I changed this code, and it works fine now:

    <?php $count = 1; ?>
    
        <?php
    		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    		$forsale_query = new WP_Query( array( 'paged' => $paged, 'post_type' => 'ridesforsale', 'order' => 'DESC', 'orderby' => 'date', 'posts_per_page' => 20) );
    	?>
        <?php while (  $forsale_query->have_posts() ) :  $forsale_query->the_post(); ?>
        <?php $imageBrandbox = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?> 
    
        ...code here...
    
        <?php $count = $count+1; ?>
          <?php
    	  	endwhile;
    		wp_reset_query();
    	  ?>
          <?php wp_reset_postdata(); ?>
    
        <div class="clearboth"></div>
    
    	<?php kriesi_pagination($forsale_query->max_num_pages); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags