我有这段代码可以从 wordpress 中获取一些元素
global $post;
$i=0;
$args = array( 'numberposts' => 5, 'category' =>5,'order'=>'DESC','orderby'=>'post_date','suppress_filters' => 0 );
$myposts = get_posts( $args );
$has_posts = true;
foreach( $myposts as $post ) : setup_postdata($post); ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
<li>
<?php if($image){ ?>
<div class="news_left"><a href="<?php the_permalink(); ?>"><img src="<?php echo $image[0]; ?>" alt="" width="191" height="132" /></a></div>
<?php } ?>
<?php
$content = apply_filters('the_content', get_the_content());
$content = explode("</p>", $content);
?>
<div class="news_right">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<span class="date">Date: <?php the_time('j/m/Y') ?></span>
<?php echo $content[1] . "</p>";//echo String::content_limit(200,'<p>'); ?>
<a href="<?php the_permalink(); ?>">Read More</a>
</div>
<div class="clear"></div>
</li>
<?php $i++; endforeach; ?>
如果类别为空,我需要设置返回短信的条件。就像没有帖子可显示,请注意帖子使用 WPML 作为语言切换器