如何在wordpress小部件中仅查询一个帖子

我正在为我的wordpress主题制作一个wordpress小部件。在小部件中, 我尝试仅查询front-page.php上的一篇文章, 为此我使用WP_query。但是问题在于, 所有帖子都可以使用。我不知道该如何解决。任何建议都会有所帮助。

我的密码

public function widget($args, $instance) {
        $posts_args = array(
            'post_type'     => 'post', 'post_per_page' => 1, 'order'         => 'DESC'
        );
        $posts_query = new WP_Query($posts_args);

        echo $args['before_widget'];

            if($posts_query -> have_posts()):
                while($posts_query->have_posts()): $posts_query->the_post();
                    echo '<div class="widget-single-content" style="background-image: url('.get_the_post_thumbnail_url().')">';
                    echo '<div class="content-box">';
                    echo '<h1><span>"</span>'.get_the_title().'<span>"</span></h1>';
                    echo '<button class="readmore-btn text-captalize">
                    <a href="'.get_the_permalink().'">Read More</a></button>';
                    echo '</div>';
                    echo '</div>';

                endwhile;
            endif;
        echo $args['after_widget'];

        //Query

    }

#1


$posts_args = array(
'post_type'      => 'post', 'numberposts' => 1, //this show how many posts to query from DB
'order'          => 'DESC', 'posts_per_page' => 1//this show how many posts display
);

每页的帖子数

来源:

https://www.srcmini02.com/63432.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37617.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?