Forums

Wp_pagenavi for Tags page (10 posts)

  1. dhiren
    Member
    Posted 9 months ago #

    can't get wp_pagenavi for tags page, it show find in front and search page. Please help...

    here goes the code:

    <?php
    $tmp_query = $wp_query;
    query_posts('showposts=3&cat=' . get_cat_ID(dp_settings('featured')));
    if (have_posts()) :
    while (have_posts()) : the_post();
    ?>

    <?php endwhile; endif; ?>
    <?php
    $wp_query = $tmp_query;
    if (have_posts()) :
    while (have_posts()) : the_post();
    ?>

  2. keesiemeijer
    moderator
    Posted 9 months ago #

    try it with something like this:

    <?php
        // create a new WP_Query object not to interfere with the original query
        $my_feature_query = new WP_Query('posts_per_page=3&cat=' . get_cat_ID(dp_settings('featured')));
     if($my_feature_query->have_posts()) : while ($my_feature_query->have_posts()) : $my_feature_query->the_post();
        ?>
    
        <?php endwhile;  endif;?>
    
        <?php
        // second paginated loop with original query
        // maybe use the following lines to get pagination to work
    
        //  $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
        // query_posts('paged='.$paged);
        ?>
        <?php
    
        if (have_posts()) :
        while (have_posts()) : the_post();
        ?>
  3. dhiren
    Member
    Posted 9 months ago #

    Thanks for reply keesiemeijer,

    But still can't get this to work, or are this related to the function?
    here the function code:

    function wp_pagenavi($before = '', $after = '', $prelabel = '', $nxtlabel = '', $pages_to_show = 6, $always_show = false) {
    	global $request, $posts_per_page, $wpdb, $paged;
    	if(empty($prelabel)) {
    		$prelabel  = '<strong>&laquo;</strong>';
    	}
    	if(empty($nxtlabel)) {
    		$nxtlabel = '<strong>&raquo;</strong>';
    	}
    	$half_pages_to_show = round($pages_to_show/2);
    	if (!is_single()) {
    		if(!is_category()) {
    			preg_match('#FROM\s(.*)\sORDER BY#siU', $request, $matches);
    		} else {
    			preg_match('#FROM\s(.*)\sGROUP BY#siU', $request, $matches);
    		}
    		$fromwhere = $matches[1];
    		$numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere");
    		$max_page = ceil($numposts /$posts_per_page);
    		if(empty($paged)) {
    			$paged = 1;
    		}
    		if($max_page > 1 || $always_show) {
    			echo "$before <div class='Nav'><span>Page $paged of $max_page</span>";
    			if ($paged >= ($pages_to_show-1)) {
    				echo '<a href="'.get_pagenum_link().'">&laquo; First</a> <strong class="on">...</strong>';
    			}
    			previous_posts_link($prelabel);
    			for($i = $paged - $half_pages_to_show; $i  <= $paged + $half_pages_to_show; $i++) {
    				if ($i >= 1 && $i <= $max_page) {
    					if($i == $paged) {
    						echo "<strong class='on'>$i</strong>";
    					} else {
    						echo ' <a href="'.get_pagenum_link($i).'">'.$i.'</a> ';
    					}
    				}
    			}
    			next_posts_link($nxtlabel, $max_page);
    			if (($paged+$half_pages_to_show) < ($max_page)) {
    				echo '<strong class="on">...</strong> <a href="'.get_pagenum_link($max_page).'">Last &raquo;</a>';
    			}
    			echo "<div class='NavEnd'></div></div> $after";
    		}
    	}
    }
  4. keesiemeijer
    moderator
    Posted 9 months ago #

    Have tried without the double slashes:

    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    query_posts('paged='.$paged);
  5. dhiren
    Member
    Posted 9 months ago #

    Yes, not tried without double slashes.

    But the pagenation still not showing, and the tag page now show ALL post.

  6. dhiren
    Member
    Posted 9 months ago #

    I'm sorry,

    The page nation is SHOWING, but it show ALL post.
    http://v-template.com/tag/2-left-sidebar

    and once I click next page, it comes with error.

  7. keesiemeijer
    moderator
    Posted 9 months ago #

    Can you paste the full template file in a pastebin, submit it and give a link to it here.

  8. dhiren
    Member
    Posted 9 months ago #

  9. dhiren
    Member
    Posted 9 months ago #

    Hi...,

    I think I had solved this problem. I use this below code (as my first post), the matter is the wp_pagenavi() function, I just update it to the latest v.2.74 and now it's work.

    <?php
    $tmp_query = $wp_query;
    query_posts('showposts=3&cat=' . get_cat_ID(dp_settings('featured')));
    if (have_posts()) :
    while (have_posts()) : the_post();
    ?>
    
    <?php endwhile; endif; ?>
    <?php
    $wp_query = $tmp_query;
    if (have_posts()) :
    while (have_posts()) : the_post();
    ?>

    Thanks keesiemeijer :)

  10. keesiemeijer
    moderator
    Posted 9 months ago #

    Well done. Glad you got it resolved.

Reply

You must log in to post.

About this Topic