主页 / 前端 / wordpress首页获取全站置顶帖子按发布时间排序

wordpress首页获取全站置顶帖子按发布时间排序

2023.05.11 05:48 227 0
最后更新于:2023.08.11 03:39 如已失效请留言

wordpress 首页获取全站置顶帖子按发布时间排序

这段代码是首页 5 篇推荐帖子,获取置顶帖子

<section class="container py-5 my-lg-5">
    <div class="row mb-5">
        <div class="col">
            <span class="text-uppercase">Blog recommend</span>
            <h2><span class="iconfont icon-fenlei me-1"></span>推荐</h2>
        </div>
        <div class="col-4 d-flex align-items-center justify-content-end">
            <a class="text-muted"  href="https://xsgc.cc/new-article">
                <small class="text-body-secondary">查看更多<span class="iconfont icon-chakangengduo ms-1"></span></small>
            </a>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12 col-lg-5 mb-4 mb-lg-0 d-none d-lg-block">
            <?php
                $query_args = array(
                    'no_found_rows' => true,
                    'posts_per_page' => 1,
                    'post__in' => get_option('sticky_posts'),
                    'ignore_sticky_posts' => 1
                );
                $query = new WP_Query($query_args);
                if ($query->have_posts()):
                $query->the_post();
            ?>
        <a href="<?php the_permalink(); ?>">
            <div class="card text-bg-dark h-100">
                <img src="<?php echo catch_the_image(); ?>" class="card-img h-100 object-fit-cover">
                <div class="card-img-overlay h-100 d-flex flex-column justify-content-end p-4">
                    <h5 class="h-2x"><?php the_title();?></h5>
                    <p class="h-2x"><?php echo wp_trim_words(get_the_content(), 40); ?></p>
                    <small class="text-secondary">
                        <span class="iconfont icon-shijian me-1"></span><?php echo timeago(get_gmt_from_date(get_the_time('Y-m-d G:i:s'))); ?>
                        <span class="iconfont icon-liulan ms-2 me-1"></span><?php post_views('', ''); ?>
                    </small>
                </div>
            </div>
        </a>
        <?php
            endif;
            wp_reset_postdata();
        ?>
        </div>
        <div class="col-md-12 col-lg-7">
            <div class="row row-cols-1 row-cols-md-2 row-cols-lg-2 g-4">
                <?php
                    $query_args = array(
                        'no_found_rows' => true,
                        'posts_per_page' => 4,
                        'post__in' => get_option('sticky_posts'),
                        'ignore_sticky_posts' => 1,
                        'offset' => 1
                    );
                    $query = new WP_Query($query_args);
                    if ($query->have_posts()) :
                    while ($query->have_posts()) :
                    $query->the_post();
                    get_template_part('mokuai/fangxingfengmian');
                    endwhile;
                    endif;
                    wp_reset_postdata();
                ?>
            </div>
        </div>
    </div>
</section>

 

下载地址

评论(0)

下载地址

赞赏

微信赞赏码
支付宝赞赏码

最新评论

  • andres  2024-10-20 09:13:00 牛啊! [原创工具] 抖音视频解析盒子V1.3 2023.10.7-来源吾
  • aa  2024-03-21 20:38:07 感性分享 Ardfry四大系列缩略图插件PSD、AI、INDD、CR2、NEF
  • Miracle  2023-12-13 10:31:20 谢谢分享 Photoshop和Illustrator的参考辅助线插件GuideGuide
  • 马总  2023-12-07 16:24:49 正需要,感谢 Ardfry四大系列缩略图插件PSD、AI、INDD、CR2、NEF
  • 11  2023-11-29 20:45:35 感谢 Photoshop和Illustrator的参考辅助线插件GuideGuide