我正在为 Wordpress 使用骨骼主题。
我有一个博客页面,每页以 3x3 布局跟随 9 个帖子,除了在 3x3 上方有一个大(最新)帖子的第一页。分页工作正常,直到帖子等于 9+1 的倍数,所以就像 19、28、37...
我意识到在第一页上放置较大的特色帖子一定会破坏它,我只是不知道如何更改它。
这就是在 bone.php 中调用导航的方式
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('«');
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('»');
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 新手。