如何將課程新增至 WordPress 主頁上的最新貼文?
P粉073857911
P粉073857911 2024-03-21 23:09:34
0
1
317

我在Wordpress中使用以下功能在主頁上顯示最新的三篇文章。 是否可以將類別 class="latest-posts-right" 加到最後一個 div,以便我可以給它另一個樣式?我怎樣才能做到這一點?

<?php
/* Show latest posts on homepage */
function latest_post() {

    $args = array(
        'posts_per_page' => 3, /* how many post you need to display */
        'offset' => 0,
        'orderby' => 'post_date',
        'order' => 'DESC',
        'post_type' => 'post', /* your post type name */
        'post_status' => 'publish'
    );
    $query = new WP_Query($args);
    if ($query->have_posts()) :
        while ($query->have_posts()) : $query->the_post();
            ?>
            <div class="latest-posts">
            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
            <p><?php the_excerpt(); ?></p>
            <div class="readmore"><a href="<?php the_permalink(); ?>">Read more »</a></div>
            </div>
            <?php
        endwhile;
    endif;
}

add_shortcode('lastest-post', 'latest_post');
?>

P粉073857911
P粉073857911

全部回覆(1)
P粉384366923

CSS 選擇器:last-child 可以為你工作

div.latest-posts:last-child{
   /* css rules */
}

div.latest-posts:nth-child(3){
   /* css rules */
}
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!