Pagination linking to first page

Perhaps you can take a look at this question and the answers and check if you really want to use query_posts() as it is not recommended while dealing with posts pagination. Why not use pre_get_posts action instead? Or you can try something like this: <?php $custom_query = new WP_Query(array( ‘post_status’ => ‘publish’, ‘post_type’ => ‘products’, … Read more

Displaying and Querying Posts with Featured image

Start by cleaning up your code; $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 3, ‘order’ => ‘asc’ ); $home_shows = new WP_Query($args); //setup your loop here if( $home_shows->have_posts() ): while( $home_shows->have_posts() ): $home_shows->the_post(); //fetch featured image if exists if ( has_post_thumbnail() ) { the_post_thumbnail(array(486,226)); } //fetch content the_content(); //etc… endwhile; endif; What output do … Read more

WordPress Query based on random taxonomy

<?php $all_books = get_terms( ‘history_books’ ); // Get all history book terms. $rand_book = $all_books[ array_rand( $all_books ) ]; // Select one at random. $related = get_posts( array( ‘posts_per_page’ => 5, ‘tax_query’ => array( array( ‘taxonomy’ => ‘history_books’, ‘terms’ => array( $rand_book->term_id ), ) ) ) ); ?> <h3> <a href=”https://wordpress.stackexchange.com/questions/104280/<?php echo get_term_link( $rand_book ) … Read more

how to get the top 10 popular blogs

If I understand you correctly, something like this should help you. global $wpdb; $results = $wpdb->get_results( “SELECT post_author, SUM(comment_count) as comments FROM {$wpdb->posts} WHERE post_type=”post” AND post_status=”publish” GROUP BY post_author ORDER BY comments DESC LIMIT 10″); This will return you 10 authors of most commented posts (with highest sum of comments count of each post … Read more

Multiple instances of query_posts

If you have 8 categories, you need 8 queries. To improve your code use WP_Query instead of query_posts: <?php $categories = get_categories(); if ( ! empty($categories) ) { ?> <ul class=”tabs”> <?php foreach ($categories as $c ) { ?> <li> <a href=”#tab<?php echo $c->term_id; ?>”> <img src=”<?php bloginfo(‘template_directory’); ?>/images/logo-<?php echo $c->slug; ?>.png” alt=”<?php echo $c->name; … Read more