Showing random content / pictures from earlier posts in a sticky post?
Showing random content / pictures from earlier posts in a sticky post?
Showing random content / pictures from earlier posts in a sticky post?
I’m afraid there is no function in WP core that will get number of unique categories based on given list of posts… So let’s take a look at your code first… There are some problems in it… There is no need to use typical loop in here – it causes many operations in background (setting … Read more
You can use WP_Query to create multiple loops in your archive template file. Each loop could pull posts from a different category if you want, just set the category parameters. In the codex there’s a whole section on multiple loops too.
The key, I think, to what you are doing is to use “offset” <div class=”col4 inner-left”> <ul class=”popular-list”> <?php query_posts(‘order=DESC&posts_per_page=3&post_type=pop’); if (have_posts()) : while (have_posts()) : the_post(); ?> <li> <a href=”https://wordpress.stackexchange.com/questions/125200/<?php the_permalink(); ?>”><?php the_title(); ?></a> </li> <?php endwhile; endif; ?> </ul> </div> <div class=”col4 inner-right”> <ul class=”popular-list”> <?php query_posts(‘order=DESC&posts_per_page=3&post_type=pop&offset=3’); if (have_posts()) : while (have_posts()) : … Read more
I have a suspicion that you’ve fallen into a misunderstanding a lot of new users fall into, but rarely realise. I suspect you have done this: This is bad, and suggests a lack of understanding about how categories work. It will also cause issues in your code when your assumptions don’t match the reality of … Read more
You could initialize a second counter variable that increments when your first counter variable increments, and use that with modulus to alternate your code blocks. First initialize two counter variables: <?php if (have_posts()) : $show_alternate = 1; $which_alternate = 1; while (have_posts()) : the_post(); ?> Then in your .pin-alternate-content output code you could do something … Read more
First, go to Settings->Reading->Blog pages show at most->25. Or change the posts_per_page in main query to 25. Then, try this code in your template: if (have_posts()) : $count = 0; $paged = ( get_query_var(‘paged’) > 1 ) ? get_query_var(‘paged’) : 1; while (have_posts()) : the_post(); $count++; if ($count <= 3 && $paged === 1) : … Read more
Assuming you have an original query that is wrapping the code you pasted, it looks like <?php wp_reset_query(); ?> is your issue, but I’m pretty sure you should be able to replace it with <?php wp_reset_postdata() ?> to get back to your original $post variable within the main query.
Whilst WordPress has gotten pretty good at db caching for loops (thumbnails, post meta, terms), it does not pre-emptively cache users (authors). So if you have 5 different authors across all the posts in your loop, that’s 10 queries (1 for the user object, 1 for the user’s meta cache stash). It’s thanks to WP_Query::setup_postdata() … Read more
The way I retrieve posts on my blog is to use the following: <?php $recentPosts = new WP_Query(); $recentPosts->query(‘showposts=5&cat=CAT_ID_GOES_HERE’); while($recentPosts->have_posts()): $recentPosts->the_post(); ?> Then you would go and create the code to control the display of each post. So for a really simple example: <h1 class=”title”><a href=”https://wordpress.stackexchange.com/questions/3170/<?php the_permalink(); ?>”><?php the_title(); ?></a></h1> Then at the end of … Read more