是否可以在静态首页上包含索引分页?
我的子主题是211,我正在尝试创建一个主页,其中有一个用于粘贴帖子的滑块,后面是带有自定义查询的最近帖子,我希望对其分页。
我创建了一个页面模板,并将该页面模板设置为静态首页。
出于某种原因,分页只有在我登录WordPress时才起作用。如果我以匿名访问者的身份访问该网站,我会得到一个404,URL看起来像“example.com/2011/09/268”,而不是“example.com/page/2”。
Am I going about this the completely wrong way?
以下是页面模板的代码:
<?php
get_header(); ?>
<div id="primary">
<div id="content" role="main">
<?php the_post(); ?>
<?php
$sticky = get_option( \'sticky_posts\' );
// Proceed only if sticky posts exist.
if ( ! empty( $sticky ) ) :
$featured_args = array(
\'post__in\' => $sticky,
\'post_status\' => \'publish\',
\'posts_per_page\' => 10,
\'no_found_rows\' => true,
);
// The Featured Posts query.
$featured = new WP_Query( $featured_args );
// Proceed only if published posts exist
if ( $featured->have_posts() ) :
$counter_slider = 0;
?>
<div class="featured-posts">
<h1 class="showcase-heading"><?php _e( \'Featured Posts\', \'twentyeleven\' ); ?></h1>
<div class="flexslider">
<ul class="slides">
<?php
// Let\'s roll.
while ( $featured->have_posts() ) : $featured->the_post();
if ( has_post_thumbnail()) : ?>
<li>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail(); ?>
<p class="flex-caption"><a href="<?php the_permalink(); ?>"
title="<?php printf( esc_attr__( \'Permalink to %s\', \'twentyeleven\' ),
the_title_attribute( \'echo=0\' ) ); ?>" rel="bookmark">
<?php the_title(); ?></a></p>
</a>
</li>
<?php
endif; // End check for post thumbnail ?>
<?php endwhile; ?>
</ul>
</div>
<?php //endif; // End check for more than one sticky post. ?>
</div><!-- .featured-posts -->
<?php endif; // End check for published posts. ?>
<?php endif; // End check for sticky posts. ?>
<?php
// Display our recent posts
// Setup for pagination of custom loop
$paged = (get_query_var(\'page\')) ? get_query_var(\'page\') : 1;
$recent_args = array(
\'order\' => \'DESC\',
\'post__not_in\' => get_option( \'sticky_posts\' ),
\'category__not_in\' => array( 46, 47 ),
\'tax_query\' => array(
array(
\'taxonomy\' => \'post_format\',
\'terms\' => array( \'post-format-aside\', \'post-format-link\', \'post-format-quote\', \'post-format-status\' ),
\'field\' => \'slug\',
\'operator\' => \'NOT IN\',
),
),
\'posts_per_page\' => 10,
\'paged\' => $paged,
);
// Our new query for the Recent Posts section.
query_posts( $recent_args );
// The first Recent post is displayed normally
//if ( $wp_query->have_posts() ) : $wp_query->the_post();
?>
<h1 class="showcase-heading"><?php _e( \'Recent Posts\', \'twentyeleven\' ); ?></h1>
<?php twentyeleven_content_nav( \'nav-above\' ); ?>
<div class="recent-posts">
<?php
if ( $wp_query->have_posts() ) :
while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<div class="recent-post">
<?php if ( "image" == get_post_format() ) :
get_template_part( \'content\', \'image\' );
else : ?>
<h2 class="entry-title">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( \'Permalink to %s\', \'twentyeleven\' ), the_title_attribute( \'echo=0\' ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
</h2>
<div class="entry-meta">
<?php twentyeleven_posted_on(); ?>
</div><!-- .entry-meta -->
<?php if( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( \'Permalink to %s\', \'twentyeleven\' ), the_title_attribute( \'echo=0\' ) ); ?>" rel="bookmark">
<?php the_post_thumbnail(\'excerpt-thumbnail\', array(\'class\' => \'alignleft\') ); endif; ?></a>
<?php the_excerpt(); ?>
<p class="comments-link">
<?php comments_popup_link( \'<span class="leave-reply">\' . __( \'Leave a Comment\', \'twentyeleven\' ) . \'</span>\', __( \'<b>1</b> Comment\', \'twentyeleven\' ), __( \'<b>%</b> Comments\', \'twentyeleven\' ) ); ?>
</p>
<?php endif; ?>
</div>
<hr />
<?php
endwhile; ?>
<?php
endif; ?>
<?php
twentyeleven_content_nav( \'nav-below\' );
// Reset because we used query_posts
wp_reset_query(); ?>
</div> <!-- End recent-posts -->
<?php //get_template_part( \'content\', \'page\' ); ?>
<?php //comments_template( \'\', true ); ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>