如何获取博客文章的精选图片,内容,上次修改日期和评论数量?

时间:2012-01-24 11:13:35

标签: wordpress blogs

我有一个wordpress网站,我想创建一个博客页面,它将显示以下内容。

  1. 博客第一行的精选图片
  2. 第二行的博客标题
  3. 第三行中的博客内容(文字)
  4. 最后更新,评论计数并在第4行发布。
  5. 我将如何做到这一点?

    Shoud我直接查询数据库还是使用一些内置函数?

    任何帮助?

1 个答案:

答案 0 :(得分:0)

query_posts( );
        while ( have_posts() ) : the_post(); 
        if( has_post_thumbnail())
        the_post_thumbnail( 'medium' );
        else {
        $photos = get_children( array('post_parent' => get_the_ID(), 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') );
            if ($photos) {
                $photo = array_shift($photos);
                echo wp_get_attachment_image($photo->ID, 'medium' );
            }
        }

        echo '<h2 class="entry-title"><a href="'.get_permalink().'" title="'.get_the_title().'">'.get_the_title().'</a></h2>'; 
        the_excerpt();

        endwhile; 
        wp_reset_query();