is_front_page 不工作

is_front_page Not working

这是我想要实现的目标:

我希望主页样式与旧帖子/分页中使用的样式不同。经过一些研究,我遇到了 is_front_page 查询,所以我创建了一个 front-page.php 文件:

<?php get_header(); ?>
<?php if(is_front_page()): ?>
<div id="slider2">
    <?php masterslider(1); ?>
</div>
<div class="main">
    <!-- <div class="slider"> 
                <div class="slidertext">


                </div> 
                <div class="sliderimg" style="background:  linear-gradient(rgba(78, 181, 224, 0.95), rgba(78, 181, 224, 0.75)), url(<?php echo esc_url( get_template_directory_uri() ); ?>/img/featured_slider.png); height: 100%; background-size: cover;"></div>
            </div> <!-- END OF SLIDER -->
    <div class="featured2">
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <div class="post_ftd">
            <img src="<?php $image_id = get_post_thumbnail_id();
                $image_url = wp_get_attachment_image_src($image_id,'post-thumb', true);
                echo $image_url[0];  ?>">
            <div class="posttext_ftd">
                    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>

                    <h4>Posted in: <?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?></h4>

                    <h5 style="float: right; margin-top: -11px;"><?php comments_number('No Comments', '1 Comment', '% Comments' );?></h5>

            </div>
        </div>
        <?php endwhile; ?>
        <?php else : ?>
        <div id="post">
            <!-- 404 Messege -->
                <h3>404 ERROR!!</h3>

            <p>Sorry we can't seem able to find what you are looking for</p>
            <p><a href="#">Click here to get back to the homepage</a>
            </p>
        </div>
        <?php endif; ?>
    </div>
    <div id="video_home_title">
            <h1> <i class="fa  fa-video-camera"></i> QEPrize Video:</h1>

    </div>
    <div id="video_home">
        <?php echo do_shortcode( "[videogallery id='qep2']"); ?>
    </div>
    <div id="height"></div>
    <nav id="pagination">
        <!-- PAGINATION FOR BLOG -->
        <ul>
            <li class="older">
                <?php next_posts_link( 'Older posts'); ?>
            </li>
            <li class="newer">
                <?php previous_posts_link( 'Newer posts'); ?>
            </li>
        </ul>
    </nav>
    <!-- END OF BLOG PAGINATION -->
    <!-- START OF POSTS -->
</div>
<?php else: ?>
<div class="main">
    <div class="slider">
        <!-- START OF SLIDER -->
        <div class="slidertext">
                <h1><a href="#">Learn more about the QEPrize Winner</a></h1>

            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
        </div>
        <div class="sliderimg" style="background:  linear-gradient(rgba(78, 181, 224, 0.95), rgba(78, 181, 224, 0.75)), url(<?php echo esc_url( get_template_directory_uri() ); ?>/img/featured_slider.png); height: 100%; background-size: cover;"></div>
    </div>
    <!-- END OF SLIDER -->
    <div class="posts">
        <!-- START OF POSTS -->
        <?php if (have_posts()) : ?>
        <?php while (have_posts()) : the_post(); ?>
        <div class="post">
            <div class="postimg">
                <img src="<?php $image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'post-thumb', true);
echo $image_url[0];  ?>" width="287" height="192">
            </div>
            <div class="posttext">
                    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>

                <ul class="postinfo">
                    <li>Posted by
                        <?php the_author_link(); ?>
                    </li>
                    <li>
                        <?php the_time( 'jS F Y'); ?>
                    </li>
                </ul>
                <?php the_content( ''); ?>
                <div class="read_more_blog"><a href="<?php the_permalink(); ?>">Read More</a>
                </div>
            </div>
        </div>
        <?php endwhile; ?>
        <nav id="pagination">
            <!-- PAGINATION FOR BLOG -->
            <ul>
                <li class="older">
                    <?php next_posts_link( 'Older posts'); ?>
                </li>
                <li class="newer">
                    <?php previous_posts_link( 'Newer posts'); ?>
                </li>
            </ul>
        </nav>
        <!-- END OF BLOG PAGINATION -->
        <?php else : ?>
        <div id="post">
            <!-- 404 Messege -->
                <h3>404 ERROR!!</h3>

            <p>Sorry we can't seem able to find what you are looking for</p>
            <p><a href="#">Click here to get back to the homepage</a>
            </p>
        </div>
        <?php endif; ?>
    </div>
    <?php endif; ?>
    <?php get_footer(); ?>

如果您只希望第一个分页页不同,则必须使用条件 if( get_query_var('paged') == 1 ): 而不是 if(is_front_page() ):