Wordpress - jetpack无限滚动无法正常工作

时间:2013-01-18 13:45:43

标签: wordpress

所以我在我的functions.php中添加了对无限滚动的支持,就像这样

add_theme_support( 'infinite-scroll', array(
    'container'  => 'content',
    'footer'     => 'page',
     'posts_per_page'    => 4
) );

这是我的模板和循环,我添加了一个id为'content'的任意div,因为jetpack显然需要你帖子的包含div作为ID,但无限滚动仍然不起作用。

<?php 


/*
    Template Name: News
*/

?>


<?php get_header(); ?>
<div class="main-content">



    <div class="content-left">
    <div id="content">

        <?php
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        query_posts('posts_per_page=&paged=' . $paged); 
        ?>


        <?php if (have_posts()) : while ( have_posts()) : the_post(); ?>

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





            <div class="entrywrapper">

                <div class="entry">




                <div class="bordertop">
                 <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
                </div> <!-- end div bordertop -->

                <div class="aligncenter grey">  
                <?php the_time('M jS, Y') ?>
                </div>
                    <div class="meta">


                <span>Posted in :<?php the_category($separator = ' / '); ?></span>
                    <div class="clearfix"></div>
                </div> <!-- end div meta -->


                <?php global $more; $more = 0; ?>
                <div class="figure">
                <?php the_post_thumbnail(); ?>
                </div> <!-- end div figure //centers thumbnail -->


                      <p class="firstparaph"> <?php the_field('main_post_meta'); ?></p>

                        <?php the_content('Continue Reading >'); ?>
                        <div class="centerm">
                         <?php comments_popup_link('No Comments', '1 Comment', '% Comments', 'comments-link', ''); ?>
                        </div>              
                    <div class="postbreaker">* * *</div> <!-- end div entrybreaker -->
                </div> <!-- end div entry -->








            <div style="clear:both"></div>


            </div> <!-- end div entrywrapper -->

            <div style="clear:both"></div>

            </div> <!-- end div post -->




    <?php endwhile; endif; ?>

        <div class="navigation">
            <div class="next-posts"><?php next_posts_link('Older Posts') ?></div>
            <div class="prev-posts"><?php previous_posts_link('Newer Posts') ?></div>
        </div>

    </div> <!-- end div ID content -->
    </div> <!-- end div content-left -->

    <div class="content-right">
        <?php get_sidebar(); ?>
    </div> <!-- end div content-right -->


    <div style="clear:both;"></div>
</div> <!-- end div main-content -->
<?php get_footer(); ?>

1 个答案:

答案 0 :(得分:0)

也许试试这个:

在functions.php中

function get_post_content() {
?>
    <div <?php post_class('clearfix') ?> id="post-<?php the_ID(); ?>">
        <div class="entrywrapper">
            <div class="entry">
                <div class="bordertop">
                 <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
                </div> <!-- end div bordertop -->
                <div class="aligncenter grey">  
                <?php the_time('M jS, Y') ?>
                </div>
                <div class="meta">
                <span>Posted in :<?php the_category($separator = ' / '); ?></span>
                    <div class="clearfix"></div>
                </div> <!-- end div meta -->
                <?php global $more; $more = 0; ?>
                <div class="figure">
                <?php the_post_thumbnail(); ?>
                </div> <!-- end div figure //centers thumbnail -->
                <p class="firstparaph"> <?php the_field('main_post_meta'); ?></p>
                <?php the_content('Continue Reading >'); ?>
                <div class="centerm">
                    <?php comments_popup_link('No Comments', '1 Comment', '% Comments', 'comments-link', ''); ?>
                </div>              
                <div class="postbreaker">* * *</div> <!-- end div entrybreaker -->
                </div> <!-- end div entry -->
            <div style="clear:both"></div>
            </div> <!-- end div entrywrapper -->

            <div style="clear:both"></div>
            </div> <!-- end div post -->
<?php
}

然后在你的博客循环文件中:

<?php 


/*
    Template Name: News
*/

?>


<?php get_header(); ?>
<div class="main-content">



    <div class="content-left">
    <div id="content">

        <?php
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        query_posts('posts_per_page=&paged=' . $paged); 
        ?>


        <?php if (have_posts()) : while ( have_posts()) : the_post(); ?>

           <!-- MY EDIT IS HERE -->
           get_post_content();

        <?php endwhile; endif; ?>

        <div class="navigation">
            <div class="next-posts"><?php next_posts_link('Older Posts') ?></div>
            <div class="prev-posts"><?php previous_posts_link('Newer Posts') ?></div>
        </div>

    </div> <!-- end div ID content -->
    </div> <!-- end div content-left -->

    <div class="content-right">
        <?php get_sidebar(); ?>
    </div> <!-- end div content-right -->


    <div style="clear:both;"></div>
</div> <!-- end div main-content -->
<?php get_footer(); ?>