搜索

首页  >  问答  >  正文

如何将课程添加到 WordPress 主页上的最新帖子?

我在Wordpress中使用以下功能在主页上显示最新的三篇文章。 是否可以将类 class="latest-posts-right" 添加到最后一个 div,以便我可以给它另一种样式?我怎样才能做到这一点?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

<?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粉073857911P粉073857911374 天前430

全部回复(1)我来回复

  • P粉384366923

    P粉3843669232024-03-22 13:03:01

    CSS 选择器:last-child 可以为你工作

    1

    2

    3

    div.latest-posts:last-child{

       /* css rules */

    }

    1

    2

    3

    div.latest-posts:nth-child(3){

       /* css rules */

    }

    回复
    0
  • 取消回复