• Resolved Damien

    (@takster)


    Hi there.

    I’m trying to figure out a way to pull articles by a vote rating stored in my database (displayed highest to lowest) then display the articles in my theme using a count, and finally, have pagination enabled with the default wordpress previous and next buttons.

    I have a three column layout, and using a count I do two articles in the first column, end, then move to the second column, do another two articles, then move to the third and final column.

    // do the vote database query part
    <?php
    $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); ?>
    
    // do the count, count/display two articles then move on
    <?php $count++; ?>
    <?php if ($count%2== 0) : ?>
    
    //count two articles off (content)
    
    <?php else : ?>
    
    //do something else 
    
    <?php endif;?>

    So far I’ve managed to pull the info needed but the count is messed up and I’m still not sure how pagination will fit into the query. I could be going about this all wrong anyway. Thanks for any advice.

  • The topic ‘query mysql, count & pagination’ is closed to new replies.