WordPress 5-在设置偏移量以排除最新帖子后,博客每页显示相同的帖子

时间:2019-03-11 16:06:54

标签: wordpress pagination

我想从帖子列表循环中排除最新的帖子,以便我可以以完全不同的样式显示它,并使其不会出现在博客的所有页面上(最新的帖子只需要在主页上) )

我尝试编辑while中的loop.php循环以将offset设置为1,但是现在该博客为每个页面显示相同的9条帖子。我尝试为我创建的posts_per_page参数设置一个paged变量和一个$args变量,但没有任何改变。

这是loop.php中的代码:

 <?php if (!have_posts()) : ?>
    <h1>Not Found</h1>
    <p>Apologies, but no results were found for the requested archive. Perhaps searching will help find a related
        post.</p>
    <?php get_search_form(); ?>
<?php endif; ?>
<?php

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
    'post_type'=> 'post',
    'offset'=>1,
    'posts_per_page'=>9,
    'paged'=>$paged
);
$query=new wp_query($args);

?>

    <div class="standard-posts">

        <?php while ($query->have_posts()) : $query->the_post(); ?>
            <div class="hentry standard-post">
                <?php $body_background = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'full'); ?>
                <a href="<?php the_permalink(); ?>" rel="bookmark">
                    <div class="preview-image"
                         style="background-image: url(<?php echo $body_background['0']; ?>)"></div>

                </a>

                <?php
                echo '<p class="category-name">';
                the_category(', ');
                echo '</p>';
                ?>
                <h2><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>

                <script type="text/javascript">var switchTo5x = true;</script>
                <script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
                <script type="text/javascript">
                    stLight.options({
                        publisher: '435df350-2dac-4199-95f6-8d8863a8de9a',
                        onhover: 'false'
                    });
                </script>

            </div>
        <?php endwhile; ?>
    </div>

<?php if ($query->max_num_pages > 1) : ?>
    <div class="page-nav">
        <?php next_posts_link('Older Posts'); ?>
        <?php previous_posts_link('Newer Posts'); ?>
    </div>
<?php endif; ?>

供参考的是index.php文件,其中包含获取最新帖子的代码:

<?php get_header(); ?>

 <div class="blog-page-container">
        <div class="blog-page-interior">
            <div class="blog-heading"  style="background-image:url('https://blueacornici.embold.net/wp-content/uploads/strat-header-bg.png');">

                <h1><?php echo wp_title("") ?></h1>
                <p class="sub-heading">Learn the latest best practices in development, design and digital marketing from out technical savvy staff.</p>
            </div>
            <div class="post-listing">
                <?php
                $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

                if(is_home() && $paged == 1) {
                    $recent_posts = wp_get_recent_posts(1);
                    foreach( $recent_posts as $recent ){ ?>
                        <?php $body_background = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID($recent) ), 'full'); ?>
                        <div class="hentry first-post" style="background-image: url(<?php echo $body_background['0'];?>)">

                            <a href="<?php get_permalink($recent); ?>" rel="bookmark">
                                <div class="preview-image" style="background-image: url(<?php echo $body_background['0'];?>)"></div>
                            </a>

                            <div class="post-gradient"></div>
                            <?php $body_background = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'full'); ?>
                            <div class="first-post-inner">
                                <span class="featured-article">featured article</span>
                                <h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
                                <?php
                                    $excerpt =  substr($recent['post_content'], 0, 327);
                                ?>
                                <div class="excerpt"><?php echo $excerpt." [...]" ?></div>
                                <a href="<?php the_permalink() ?>" class="read-article">Read Full Article</a>
                            </div>
                        </div>
                        <?php
                    }
                    wp_reset_query();
                }
                ?>

                <?php get_template_part('loop', 'index'); ?>
            </div>
        </div>
    </div>

<?php get_footer(); ?>

0 个答案:

没有答案