带有最新帖子的静态首页分页

时间:2012-03-10 作者:jjeaton

是否可以在静态首页上包含索引分页?

我的子主题是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(); ?>

1 个回复
最合适的回答,由SO网友:fuxia 整理而成

创建文件front-page.php 作为副本index.php. 在页面顶部添加滑块代码。WordPress现在将为您处理分页。

如果需要第一页上的滑块,请仅将其包装为条件:

// First page
if ( empty ( $GLOBALS[\'paged\'] ) or 1 == $GLOBALS[\'paged\'] )
{
    // slider code
}
// the regular loop follows

结束

相关推荐

URL rewrites and pagination

我必须说,我完全是Wordpress自定义URL重写的nooby。在过去的几天里,我一直在寻找如何确定和编写正确的URL重写模式的清晰解释。我有一个自定义页面模板,它使用传递给它的查询变量,例如。http://example.com/pagename?user=username. 在这里,“pagename”指的是自定义页面模板,“user”指的是自定义查询变量。我需要使用URL来表示它http://example.com/pagename/username.我还需要上面的内容进行分页。所以http://