在我的主页中,我有不同布局的内容框。每个框都有一个图像和与单个帖子相对应的帖子标题。我应该如何仅使用一个get\\u posts()并以不同的格式设置框的布局?
示例:
H1 Post-title 1 Image 1 BIG H2 Post-title 2 Image 2 MEDIUM H3 Post-title 3 Image 3 SMALL
在我的主页中,我有不同布局的内容框。每个框都有一个图像和与单个帖子相对应的帖子标题。我应该如何仅使用一个get\\u posts()并以不同的格式设置框的布局?
示例:
H1 Post-title 1 Image 1 BIG H2 Post-title 2 Image 2 MEDIUM H3 Post-title 3 Image 3 SMALL
正如@MridulAggarwal所言,这是您面临的一项非常基本的PHP任务:
$wpse69584_posts = get_posts( array( /* Your Arguments */ ) );
echo $post[0][\'post_title\'];
echo isset( $post[0]->post_excerpt )
? apply_filters( \'the_excerpt\', $post[0]->post_excerpt )
: apply_filters( \'the_content\', $post[0]->post_content )
;
// etc.
或者,如果使用循环,则更容易:global $wpdb;
if ( have_posts() )
{
while( have_posts() )
{
the_post();
if ( 1 <= $wpdb->current_post )
{
$thumb_size = \'BIG\';
}
// Add \'MEDIUM\' to 2nd post and \'SMALL\' to each other
else
{
$thumb_size = ( 2 == $wpdb->current_post ? \'MEDIUM\' : \'SMALL\' );
}
echo \'<article \'.get_post_class( "post-number-{$wpdb->current_post}" ).\'>\';
echo "<h{$wpdb->current_post}>";
the_title();
echo "</h{$wpdb->current_post}>";
the_content();
the_post_thumbnail( get_the_ID(), $thumb_size );
echo \'</article>\';
}
}
请注意,这对于较大的数字不起作用,因为6
, 像$wpdb->current_post
仍然会增加,但根本没有<h7>
以及以下内容;)我正在使用类似的帖子插件http://wordpress.org/extend/plugins/similar-posts/, 我希望类似的帖子显示在同一行,而不是列表。。。如链路1、链路2、链路3、链路4而不是链接1链接2链接3链接4几天前,我在wordpress论坛和插件的官方网站上发布了这篇文章,但仍然没有答案。。。救救我!(我对编码知之甚少,所以请尽量具体,如果你给我代码,请解释每一行的作用,以便我可以学习)谢谢补充信息:我正在使用插件的大部分默认设置,我认为我所做的唯一更改是将其设置为只考虑标签