-2

我想将博客设置为主页。我用下面的代码创建了一个front-page.php。

该代码将最近的帖子显示为主页。我想使用 1 个特定博客作为主页,而不是最近的博客或粘性帖子。

这是示例站点。博客用作主页。如果发布了新博客,主页不会更改。

https://height-comparison.com/

原帖: 如何让Wordpress在首页只显示一篇带有评论和评论表格的帖子?

<?php get_header(); ?>
<div class="blog">
    <section>
        <div class="container">
            <div class="row">
                <div class="blog-sidebar">
                    <?php get_sidebar(); ?>
                </div>
                <div class="span8">
                <?php $articles = new WP_Query(array(
                                    'post_type' => 'post',
                                    'post_status' => 'publish',
                                    'posts_per_page' => 1
                                ));?>
                    <?php  while ($articles->have_posts()): $articles->the_post(); ?>
                        <article id="post-<?php the_ID(); ?>" role="article">
                            <header>
                                <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail( 'wpbs-featured' ); ?></a> 
                            <section class="post_content clearfix" >
                                 <?php the_content(); ?>
                            </section> 
                        </article>
                    <?php endwhile; ?> 
                  <?php comments_template('',true); ?>
                </div>
            </div>
        </div>
    </section>
</div>

<?php get_footer(); ?>

先感谢您。

4

1 回答 1

0

您可以使用置顶帖子示例wpbeginner 置顶帖子

<?php get_header(); ?>
<div class="blog">
    <section>
        <div class="container">
            <div class="row">
                <div class="blog-sidebar">
                    <?php get_sidebar(); ?>
                </div>
                <div class="span8">
                <?php 

                /* Get all sticky posts */
                $sticky = get_option( 'sticky_posts' );
                 
                /* Sort the stickies with the newest ones at the top */
                rsort( $sticky );
                 
                /* Get the 5 newest stickies (change 5 for a different number) */
                $sticky = array_slice( $sticky, 0, 5 );
                 
                /* Query sticky posts */



                $articles = new WP_Query(array(
                                    'post_type' => 'post',
                                    'post_status' => 'publish',
                                    'post__in' => $sticky,
                                    'ignore_sticky_posts' => 1,
                                    'posts_per_page' => 1
                                ));?>
                    <?php  while ($articles->have_posts()): $articles->the_post(); ?>
                        <article id="post-<?php the_ID(); ?>" role="article">
                            <header>
                                <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail( 'wpbs-featured' ); ?></a> 
                            <section class="post_content clearfix" >
                                 <?php the_content(); ?>
                            </section> 
                        </article>
                    <?php endwhile; ?> 
                  <?php comments_template('',true); ?>
                </div>
            </div>
        </div>
    </section>
</div>

<?php get_footer(); ?>
于 2021-08-05T15:48:44.033 回答