• I am trying to create a page that only shows posts listed under the category called “Video”. I am in hopes to limit the number of post per page to 4. I have searched all over and everything I have tried has not worked. Below is the code I have so far. ‘Cat’ 8 represents the “Video” category. If anyone knows how or where I need to alter this code, I would really appreciate the help!

    [code moderated - please follow the forum guidelines for posting code]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Jess

    (@jessn)

    Try one of these:

    <?php $paged = (get_query_var('paged')) ?
    get_query_var('paged') : 1;
    query_posts("category_name=video&showposts=4&paged=$paged"); ?>
    <?php while (have_posts()) : the_post(); ?>
    
    ...loop stuff
    
    <?php endwhile; ?>
    <?php if (have_posts()) :
    $my_query = new WP_Query('cat=8&showposts=4'.'&paged='.$paged);
    while ( $my_query->have_posts() ) : $my_query->the_post();
    ?>
    
    ... loop stuff
    
    <?php endwhile; endif; ?>
    Thread Starter Thaddeus Briggs

    (@incubus820)

    Jessn,

    Thank you very much for the response. I tried both of the options you provided. The first one removed all posts and left the content blank. The second did not add any additional posts. I am guessing that there is something wrong with my initial code and that is why it did not work. If possible could you take a look at my code using your second suggestion? I am very new to PHP and I am guessing I have made a silly mistake somewhere. Here is a pastebin link to the code… http://pastebin.com/vdZQjw5p

    Jess

    (@jessn)

    Sorry for the late reply. I see the issue and I apologize – it was an issue with the code I gave you. In that second example you shouldn’t have the top line in there. So it should read:

    <?php
    $my_query = new WP_Query('cat=8&showposts=4'.'&paged='.$paged);
     while ( $my_query->have_posts() ) : $my_query->the_post();
    ?>
    
    <article <?php post_class() ?> id="post-<?php the_ID(); ?>">
    
    <div class="title-box-secondary">
    
    <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    
    <p class="edit-link"><?php edit_post_link(); ?></p>
        <?php endwhile; ?>
    Thread Starter Thaddeus Briggs

    (@incubus820)

    I tried the new code and it is now removing all posts and giving me a blank area. Just in case I messed something up on my end, I created another pastebin link.

    http://pastebin.com/02s6mAaj

    I really do appreciate your time and your help. If you know what may be causing this error please let me know.

    Jess

    (@jessn)

    Right. See the third line, how the loop starts with “while”? Some loops have “if have posts, while have posts”. This one doesn’t have the “if” statement, so you can’t have endif at the end of your loop.

    So remove everything after the “endwhile” – this code here:

    <?php include (TEMPLATEPATH . '/_/inc/nav.php' ); ?>
    
    <?php else : ?>
    
    <h2>No Posts Found</h2>
    
    <?php endif; ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom Loop With Pagination’ is closed to new replies.