我正在尝试在single.php
的WordPress博客网站上添加相关帖子,但它在长列中显示有没有办法在2列中显示?
这是我的代码
<?php
$orig_post = $post;
global $post;
$term = wp_get_post_categories($post->ID);
if ($term) {
$cat_ids = array();
foreach($term as $individual_cat) $cat_ids[] = $individual_cat->term_id;
$args=array(
'cat_in' => $cat_ids,
'post__not_in' => array($post->ID),
'posts_per_page'=>4, // Number of related posts to display.
'caller_get_posts'=>1
);
$my_query = new wp_query( $args );
while( $my_query->have_posts() ) {
$my_query->the_post();
?>
<div class="relatedthumb">
<ul>
<li><a rel="external" href="<? the_permalink()?>"><?php the_post_thumbnail(array(55,55)); ?><?php the_title(); ?></a></li>
</ul>
</div>
<?php }
}
$post = $orig_post;
wp_reset_query();
?>
以下是我想要的图片
请帮忙!
答案 0 :(得分:1)
您可以使用CSS制作它。添加到您的CSS文件下一个代码:
.relatedthumb > ul:after {
content:'';
display:block;
clear:both;
}
.relatedthumb > ul > li {
width:50%; //You need to check that, if does not work - change it to 45%;
float:left;
}