• Resolved unlimit3d1

    (@unlimit3d1)


    Hi
    I added successfully a secondary loop in my theme in home.php, but after that the pagnitation stop working , can any body helps me

    this is the code i use:

    [please mark any posted code – http://codex.ww.wp.xz.cn/Forum_Welcome#Posting_Code – the code below is partially broken]

    <?php query_posts('category_name=news &posts_per_page=3');?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    	<?php the_title(); ?>
    	<?php the_excerpt ();?>
    <?php endwhile; endif; ?>
    
    <?php wp_reset_query(); ?>
    
    <?php query_posts('cat=-13,-15');?>
    <?php if(have_posts()): while(have_posts()):the_post();?>
    	<?php the_time('F j, Y'); ?>
    	<?php $category = get_the_category(); if($category[0]){echo '<a>term_id ).'">'.$category[0]->cat_name.'</a>';}?>
    	<?php comments_popup_link( 'Няма коментари', '1 коментар', '% коментара', 'comments-link', 'Коментарите за тази публикация са изключени');?>
    	<?php if (function_exists('has_post_thumbnail') && has_post_thumbnail()) the_post_thumbnail();?>
    	<?php the_title(); ?>
    	<?php the_excerpt ();?>
    	<?php endwhile; endif;?>
    <?php posts_nav_link(); ?>
Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter unlimit3d1

    (@unlimit3d1)

    Thanks for the replay but, can you be a little more specific how exactly to do that… i am a new to wordpress development

    When i use this
    <?php $my_query = new WP_Query('cat=-13,-15');?>
    page navigation works but displays categories which i don’t want to display

    What about changing Category ID’s ?

    Thread Starter unlimit3d1

    (@unlimit3d1)

    No, it’s not that…

    what are you trying to paginate?
    – the first loop or the second loop?

    what is the current full code of the second loop?

    Thread Starter unlimit3d1

    (@unlimit3d1)

    Trying to paginate the second loop.
    The code looks like this:

    <?php query_posts('category_name=news &posts_per_page=3');?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    	<?php the_title(); ?>
    	<?php the_excerpt ();?>
    <?php endwhile; endif; ?>
    
    <?php wp_reset_query(); ?>
    <?php $my_query = new WP_Query('cat=-13,-15');?>
    <?php if(have_posts()): while(have_posts()):the_post();?>
    	<?php the_time('F j, Y'); ?>
    	<?php $category = get_the_category(); if($category[0]){echo '<a>term_id ).'">'.$category[0]->cat_name.'</a>';}?>
    	<?php comments_popup_link( 'Няма коментари', '1 коментар', '% коментара', 'comments-link', 'Коментарите за тази публикация са изключени');?>
    	<?php if (function_exists('has_post_thumbnail') && has_post_thumbnail()) the_post_thumbnail();?>
    	<?php the_title(); ?>
    	<?php the_excerpt ();?>
    	<?php endwhile; endif;?>
    <?php posts_nav_link(); ?>

    Paginate works now, but displays categories which i don’t want to display.

    Trying to paginate the second loop.

    in this case, try to switch the code for the loops; i.e. use WP_Query() for the first loop, and query_posts() for the second loop;
    example:

    <?php $my_query = new WP_Query('category_name=news &posts_per_page=3');?>
    <?php if ( $my_query->have_posts() ) : while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
    	<?php the_title(); ?>
    	<?php the_excerpt ();?>
    <?php endwhile; endif; wp_reset_postdata(); ?>
    
    <?php query_posts('cat=-13,-15&paged='.get_query_var('paged'));?>
    <?php if(have_posts()): while(have_posts()):the_post();?>
    	<?php the_time('F j, Y'); ?>
    	<?php $category = get_the_category(); if($category[0]){echo '<a>term_id ).'">'.$category[0]->cat_name.'</a>';}?>
    	<?php comments_popup_link( 'Няма коментари', '1 коментар', '% коментара', 'comments-link', 'Коментарите за тази публикация са изключени');?>
    	<?php if (function_exists('has_post_thumbnail') && has_post_thumbnail()) the_post_thumbnail();?>
    	<?php the_title(); ?>
    	<?php the_excerpt ();?>
    	<?php endwhile; endif;?>
    <?php posts_nav_link(); ?>
    Thread Starter unlimit3d1

    (@unlimit3d1)

    Works perfectly, thank you very much 🙂

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Pagnitation stops working after adding a second loop’ is closed to new replies.