• Resolved Damien

    (@takster)


    I’m trying to add pagination to a custom query that pulls the top voted articles from the DB. After every two articles I’m trying to insert something, via a count. So far my efforts have been pretty bad, the count is screwed and I have no idea how pagination fits in.

    so…
    -Grab top voted posts & order them.
    -After every two posts/articles, insert extra content, using a count.
    -pagination needed for my many pages of content.

    <?php
    // grab top voted posts in order (works okay)
    
    $query_sql = "SELECT like_pid FROM " . $wpdb->prefix ."likes_count ORDER BY like_count DESC";
    $query_result = $wpdb->get_col( $wpdb->prepare ($query_sql, OBJECT));
    if ($query_result) {
    foreach ($query_result as $post_id) {
    $post = &get_post( $post_id );
    setup_postdata($post);
    ?>
    
    // Now count out two articles (fail?)
    
    <?php $count++; ?>
    <?php if ($count%2== 0) : ?>
    
    // Show the two articles
    
    <?php else : ?>
    
    //Now do something else
    
    <?php endif;?>
    <?php } ?>
    <?php } ?>
    
    <div class="next"> <?php next_posts_link('&raquo;' ,0); ?></div>
    <div class="previous"> <?php previous_posts_link('&laquo;' ,0); ?>

    Any help appreciated much.

Viewing 1 replies (of 1 total)
  • Thread Starter Damien

    (@takster)

    Solved everything except getting pagination working with my custom query, not sure how '$wp_query->query('showposts=5'.'&paged='.$paged); fits in here.

    My working loop, without pagination. Any working tips on fitting pagination into my loop here and I owe you a beer or two.

    <?php global $wpdb;
    $query_sql = "SELECT like_pid FROM " . $wpdb->prefix ."likes_count ORDER BY like_count DESC LIMIT 6 OFFSET 0";
    $query_result = $wpdb->get_col( $wpdb->prepare ($query_sql, OBJECT));
    if ($query_result) {
    foreach ($query_result as $post_id) {
    $post = &get_post( $post_id );
    setup_postdata($post); ?>
    
    <?php $count++;
    if ($count%2== 0) : ?>
    
    <-- do the loop, count out two articles -->
    
    <?php else : ?>
    
    <-- do something after every two articles -->
    
    <?php endif;?>
    
    <?php } ?>
    <?php } ?> //ugly but works
Viewing 1 replies (of 1 total)
  • The topic ‘Paginate WordPress Query?’ is closed to new replies.