2012-02-20 59 views
0

我发现这个代码用于在缩略图中显示最近发布的缩略图。它出现在我非常喜欢的网格格式中。我想在每个缩略图图像下添加帖子的标题。我可以设法通过使用the_title()获得标题节目;但之后它不会保持网格状态,而是变成一个列表。我将不胜感激任何帮助。由于最近发布的缩略图 - 想要在图片下方显示标题

使用的CSS是:

.attachment-thumbnail { 
height:150px; 
width:150px; 
padding:5px; 
background:#fff; 
margin:5px 5px 0 0; 
} 

代码:

<?php 
$my_query = new WP_Query('showposts=12&amp;amp;amp;amp;orderby=rand'); 
if($my_query->have_posts()) { 
while ($my_query->have_posts()) : $my_query->the_post(); 
?> 

<?php 
$attachments = get_posts(array(
'post_type' => 'attachment', 
'number_posts' => 1, 
'post_status' => null, 
'post_parent' => $my_query->post->ID, 
)); 
if ($attachments) { 
?> 

<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> 

<?php 
$thumbnail_id = $attachments[0]->ID; 
echo wp_get_attachment_image($thumbnail_id); 
} 
endwhile; 
} 
wp_reset_query(); 
?> 

回答

0

这将会是让你知道,被分配到标题文本时,它的CSS属性介绍到您正在创建的页面,因为这可能是将网格变成列表。我认为这里最好的方法是将缩略图/标题对包装在div中,并使这些div具有“display:inline”属性,以便div并排显示,而不是彼此重叠。

+0

感谢您的回复。这是唯一的CSS,缩略图显示为网格,但只要我添加标题,它就成为一个列表。我确实尝试过一个div,但我对这一切都不太满意。 .attachment-thumbnail { height:150px; width:150px; padding:5px; background:#fff; margin:5px 5px 0 0; } – user1192684 2012-02-20 04:51:29

+0

菲尔,在这里必须有额外的CSS,你可以改变以获得你想要的效果。您是否尝试过使用Chrome中的代码检查器或Firefox中的FireBug来查看这些元素? – 2012-02-21 00:07:35