如何获取博客文章的特色图片、内容、最后修改日期和评论数?

发布于 2024-12-28 18:53:57 字数 213 浏览 1 评论 0原文

我有一个 WordPress 网站,我想在其中创建一个博客页面,该页面将显示以下内容。

  1. 第一行是博客的特色图片
  2. 第二行是博客标题 第三
  3. 行是博客内容(文本)
  4. 最后更新、评论计数和发布者在第四行。

我该怎么做?

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

有什么帮助吗?

I have a wordpress site in which I want to create a blog page which will display the following things.

  1. The blog's featured image in first line
  2. The blog title in the second line
  3. The blog content(text) in the third line
  4. The last update, comments count and posted by in the 4th line.

How will I do this?

Shoud I directly query the database or use some builtin functions?

Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幻梦 2025-01-04 18:53:57
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();
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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文