dongzhiyong8577 2012-02-20 03:34
浏览 55

最近的帖子缩略图 - 想在图片下方显示标题

I have found this code for showing thumbnails as recent posts in a widget. It appears in a grid format which I like very much. I would like to add the title of the post below each thumbnail images. I can manage to get the title show by using the_title(); but then it does not stay as a grid but turns into a list. I would appreciate any help. Thanks

The css used is:

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

Code:

<?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();
?>

  • 写回答

1条回答 默认 最新

  • dsfsw1233 2012-02-20 04:22
    关注

    It'd be helpful to know the CSS attributes that are being assigned to the title text when it's introduced to the page you're creating as that's likely what's turning your grid into a list. I would think the best way forward here is to wrap the thumbnail/title pairs in a div and to make those divs have the attribute "display: inline" so that the divs appear side by side rather than on top of each other.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端