How to Display a Single Post Excerpt

the_excerpt() is one of a few template tags that do not accept a post ID as a parameter. Instead, you need to set up the global $post, run your tags, then restore it: if ( $_post = get_post( 10 ) ) { setup_postdata( $post = $_post ); the_excerpt(); // Any other template tags for this … Read more

Better way to display posts from specific categories, in a grid layout

I think the general suggestion is to use WP_Query instead of query_posts partly because query_posts used WP_query in a simplified way and can cause problems down the road. So for sure check out the WP_Query page, specifically the Multiple Loops example: http://codex.wordpress.org/Class_Reference/WP_Query#Multiple_Loops So the code using WP_Query would look something like this: <?php $counter = … Read more

How to split a loop into two columns

You will need to create css classes for a left and right column (you can use bootstrap if you like) after creating the classes try this <div class=”headlines” data-interval=”<?php echo ($interval>0)?$interval*1000:’false’; ?>”> <ul> <?php $i = 0; while ( $r->have_posts() ) { $r->the_post(); if($i % 2 == 0){ //even line ?> <li class=”left-col”><a href=”https://wordpress.stackexchange.com/questions/191730/<?php the_permalink(); … Read more

How to use WP_Query to display many posts?

The p (post) paremeter for WP_Query accetps a single value only: $args = array( ‘p’ => 100 ); For multiple posts use post__in and pass an array of post ids: $args = array( ‘post__in’ => array(100, 102, 105) ); See Post & Page Paremters for further clarification.

How to pass many ids in post__in?

Don’t concatenate your id values into a comma separate string otherwise you will have to explode() by comma delimiter which is pointless, instead, if you are getting IDs from some other business logic as evidenced in your iteration over $rows, then build an array of IDs as per the following example: $ids = array(); foreach … Read more

Query posts by specific word on title

The answer to this question is here. The full credit of the answer to my question goes for the author of the answer birgire. All I had to do was slightly change is plugin “Support for post name like in WP_Query” turning it into a function like this: add_filter( ‘posts_where’, ‘title_like_posts_where’, 10, 2 ); function … Read more