Wordpress Pagination在第一页上添加了精选帖子

时间:2013-03-27 18:50:22

标签: php wordpress

我正在使用Wordpress的骨骼主题。

我有一个博客页面,在3x3布局中每页有9个帖子,除了在3x3上方有一个大(最新)帖子的第一页。分页工作正常,直到帖子等于9 + 1的倍数,所以像19,28,37 ...

我意识到在第一页上放置较大的精选帖子必须打破它,我只是无法弄清楚如何改变它。

这是在bones.php中调用nav的方式

    function bones_page_navi($before = '', $after = '') {
    global $wpdb, $wp_query;
    $request = $wp_query->request;
    $posts_per_page = intval(get_query_var('posts_per_page'));
    $paged = intval(get_query_var('paged'));
    $numposts = $wp_query->found_posts;
    $max_page = $wp_query->max_num_pages;
    if ( $numposts <= $posts_per_page ) { return; }
    if(empty($paged) || $paged == 0) {
        $paged = 1;
    }
    $pages_to_show = 7;
    $pages_to_show_minus_1 = $pages_to_show-1;
    $half_page_start = floor($pages_to_show_minus_1/2);
    $half_page_end = ceil($pages_to_show_minus_1/2);
    $start_page = $paged - $half_page_start;
    if($start_page <= 0) {
        $start_page = 1;
    }
    $end_page = $paged + $half_page_end;
    if(($end_page - $start_page) != $pages_to_show_minus_1) {
        $end_page = $start_page + $pages_to_show_minus_1;
    }
    if($end_page > $max_page) {
        $start_page = $max_page - $pages_to_show_minus_1;
        $end_page = $max_page;
    }
    if($start_page <= 0) {
        $start_page = 1;
    }
    echo $before.'<nav class="page-navigation"><ol class="bones_page_navi clearfix">'."";
    if ($start_page >= 2 && $pages_to_show < $max_page) {
        $first_page_text = "First";
        echo '<li class="bpn-first-page-link"><a href="'.get_pagenum_link().'" title="'.$first_page_text.'">'.$first_page_text.'</a></li>';
    }
    echo '<li class="bpn-prev-link">';
    previous_posts_link('&laquo;');
    echo '</li>';
    for($i = $start_page; $i  <= $end_page; $i++) {
        if($i == $paged) {
            echo '<li class="bpn-current">'.$i.'</li>';
        } else {
            echo '<li><a href="'.get_pagenum_link($i).'">'.$i.'</a></li> <!--'.$paged.' is paged and '.$end_page.' is end page. '.$numposts.' is numposts '.$max_page.' is maxpage'.$posts_per_page.'-->'; // **ISSUE LIES HERE WITH TOO MANY PAGES
        }
    }
    echo '<li class="bpn-next-link">';
    next_posts_link('&raquo;');
    echo '</li>';
    if ($end_page < $max_page) {
        $last_page_text = "Last";
        echo '<li class="bpn-last-page-link"><a href="'.get_pagenum_link($max_page).'" title="'.$last_page_text.'">'.$last_page_text.'</a></li>';
    }
    echo '<a href="'.home_url().'/about#users" class="browse mobile-hide">Browse authors</a></ol></nav>'.$after."";
}

这就是我将最新帖子放在索引页面上的方式。

  <?php if (have_posts()) : ?>
                    <?php $post = $posts[0]; $c=0;?>
                    <?php while (have_posts()) : the_post(); ?>

                    <?php $c++;
                    if( !$paged && $c == 1) : // code for the first post  ?>

                    <div><article id="post-<?php the_ID(); ?>" <?php post_class('clearfix blog first-blog'); ?> role="article">

                        <header class="article-header">

                            <?php if ( has_post_format( 'link' )) { ?>

                            <a href="<?php echo get_post_meta($post->ID, 'link_url', true); ?>" rel="bookmark" title="Visit link: <?php the_title_attribute(); ?>" target="_blank">

                            <?php } else { ?>

                            <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">

                            <?php }; ?>

                                <div class="date">
                                    <time class="updated" datetime="<?php echo the_time('Y-m-j'); ?>" pubdate>
                                        <span class="month"><?php the_time('M'); ?></span>
                                        <span class="day"><?php the_time('j'); ?></span>
                                        <span class="year"><?php the_time('Y'); ?></span>
                                    </time>
                                </div>


                                <?php if ( has_post_format( 'link' )) {
                                  echo '<div class="link"><i class="icon-link"></i></div>';
                                } ?>
                                <h1 class="h2"><?php the_title(); ?></h1>


                            </a>

                        </header> <!-- end article header -->

                        <?php if ( has_post_format( 'link' )) {
                                  echo '';
                        } else { ?>  

                        <div class="blog-body clearfix">

                            <?php if ( has_post_format( 'video' )) {
                                echo '<div class="eightcol first vid">'.get_post_meta($post->ID, 'video_url', true).'</div>'; 
                             } else { ?>

                            <a class="image mobile-hide" href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
                                <?php the_post_thumbnail('large', array('class' => 'mobile-hide eightcol first')); ?>
                            </a>

                            <?php } ?>

                            <section class="entry-content clearfix mobile-hide fourcol last">

                                <p class="byline"><?php _e('by', 'bonestheme'); ?> <span class="author"><?php the_author_posts_link(); ?></span></p>

                                <?php the_content( 'Continue reading...' ); ?>
                            </section> <!-- end article section -->

                        </div><!-- end blog body -->

                        <?php } ?>

                    </article></div> <!-- end article -->

抱歉,我还是PHP的新手。

1 个答案:

答案 0 :(得分:0)

因此,任何人都很好奇,我通过包括if(($numposts%9)==1){ $max_page=$end_page=$end_page-1; }if((($numposts%9)==1) && ($paged == ($max_page))) { } else { next_posts_link('&raquo;'); }来解决这个问题,不确定这是否是正确的形式,我确信它可以清理,但它有效!< / p>