【问题标题】:Wordpress - jetpack infinite scroll not workingWordpress - 喷气背包无限滚动不起作用
【发布时间】:2013-01-18 13:45:43
【问题描述】:

所以我在我的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(); ?>

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    不妨试试这个:

    在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(); ?>
    

    【讨论】:

      猜你喜欢
      • 2017-07-10
      • 1970-01-01
      • 2016-09-03
      • 2021-11-22
      • 2022-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-17
      相关资源
      最近更新 更多