Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>&lt;?php $myposts = get_posts( $args ); if($myposts){ //found posts }else{ //no posts } ?&gt; </code></pre> <p><strong>UPDATE</strong>: PLEASE check if the code works probably and THEN compare it with your code, i have commented on the changes i made, so its your chance to learn:</p> <pre><code>$i=0; $args = array( 'numberposts' =&gt; 5, 'category' =&gt;5,'order'=&gt;'DESC','orderby'=&gt;'post_date','suppress_filters' =&gt; 0 ); $myposts = get_posts( $args ); //check if $myposts if(!$myposts){ //the $myposts has no posts, print the error message echo "&lt;li&gt;"; echo "This category has zero posts"; echo "&lt;/li&gt;"; }else{ //the category has one more or more posts $has_posts = true; foreach( $myposts as $post ) : setup_postdata($post); ?&gt; &lt;?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post-&gt;ID ), 'single-post-thumbnail' ); ?&gt; &lt;li&gt; &lt;?php if($image){ ?&gt; &lt;div class="news_left"&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;img src="&lt;?php echo $image[0]; ?&gt;" alt="" width="191" height="132" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;?php } ?&gt; &lt;?php $content = apply_filters('the_content', get_the_content()); $content = explode("&lt;/p&gt;", $content); ?&gt; &lt;div class="news_right"&gt; &lt;h2&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt; &lt;span class="date"&gt;Date: &lt;?php the_time('j/m/Y') ?&gt;&lt;/span&gt; &lt;?php echo $content[1] . "&lt;/p&gt;";//echo String::content_limit(200,'&lt;p&gt;'); ?&gt; &lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;Read More&lt;/a&gt; &lt;/div&gt; &lt;div class="clear"&gt;&lt;/div&gt; &lt;/li&gt; &lt;?php $i++; endforeach; } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload