Post per page not working if no category specified
If you want to change your array to exclude sticky, then this should work get_posts( array( ‘post__not_in’ => get_option( ‘sticky_posts’ ), ‘posts_per_page’ => 1 ) );
If you want to change your array to exclude sticky, then this should work get_posts( array( ‘post__not_in’ => get_option( ‘sticky_posts’ ), ‘posts_per_page’ => 1 ) );
Your examples are showing two different thing The first one is looping over categories and the second is looping over posts, so the answer in this case is simple and depends on what you need to loop over (posts or categories). No if you meant when should you use query_posts() vs. get_posts() vs. WP_Query then … Read more
use echo right before functions. echo get_permalink($ancestorsID[0]); echo get_the_title($ancestorsID[0]);
Why not just use the_ID() which will always be unique and won’t require any extra code to be used.
You’re incrementing $count twice in every iteration of the loop, the first if will always be false and the second will always be true.
The content is the same because the loops are the result of the get_posts() call which does not take into account the page you are on. In short you are not looping through the results of your WP_Query but instead the get_posts() . Try replacing get_posts and the foreach with a while loop using the … Read more
this is your answer… however like Kaiser said, you should really take some time to read a little… <?php $i=0; if ( have_posts() ) while ( have_posts() ) : the_post(); if($i==0) { ?> // YOUR FIRST POST CONTENT } else if(($i==1) || ($i==2) || ($i==3)) { // POST 2, 3, 4 } else { // … Read more
$count = 1; is set in the while loop, so every time the loop runs it sets to 1 again. Place it before your loop and it will work. $count = 1; if (have_posts()) : while (have_posts()) : the_post(); Ow and the $count++ is outside the loop so it will only run after all the … Read more
Use the_excerpt() instead of the_content() – the_content() will only cut off if you do it manually.
I’m not sure of the context for this, but query_posts probably isn’t what you want to use. (See this answer). (Untested). I would use get_posts: $posts = get_posts(array( ‘numberposts’=>-1, ‘category’=>0 )); And then use wp_list_pluck to get the titles: $post_titles = wp_list_pluck($posts,’post_title’); $post_titles = array_map(‘esc_html’,$post_titles); Finally, the php implode function an list them with commas: … Read more