简体   繁体   English

Jetpack无限滚动不起作用

[英]Jetpack Infinite Scroll not working

I have been trying to get infinite scroll to work but can not seem to get it to work. 我一直在尝试使无限滚动工作,但似乎无法使其工作。

I have three files the post loop content-post-ft.php , the functions.php and then my front page where the posts are loading frontpage.php 我有三个文件:post循环content-post-ft.phpthe functions.php以及我的首页,其中的帖子正在加载frontpage.php

Functions.php Functions.php

  add_theme_support( 'infinite-scroll', array(
  'container' => 'main-content',
  'type' => 'scroll',
  'footer' => 'foot',
  'render' => 'infinite_scroll_render'
   ));

 function infinite_scroll_render() {
   get_template_part( 'content-post-ft', 'standard' );
  }

content-post-ft.php content-post-ft.php

<div class="hub-cont">
<?php

 $thumb_id = get_post_thumbnail_id();
$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail-size', true);
$thumb_url = $thumb_url_array[0];
 ?>
<div id="newsitem">
<div id="newsimg" style="background-image: url('<?php echo $thumb_url ?>')">
<a href="<?php the_permalink(); ?>"></a>
</div>
 <div id="newsname"> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>          </div>
 <div id="newstext"><?php $text = $post->post_content; $trimmed = wp_trim_words( $text, 40, null );   echo $trimmed; ?></div>
 <div class="clear"></div>
 </div>

 <?php
// endwhile;
// endif;

wp_reset_postdata();?>

</div>

Frontpage.php Frontpage.php

<div id="main-content">
 <?php

 $myargs = array (
 //'showposts' => 2,
'post_type' => 'post',
'category_name' => 'News'
);
$myquery = new WP_Query($myargs);
if($myquery->have_posts() ) :
while($myquery->have_posts() ) : $myquery->the_post();
    get_template_part( 'content-post-ft', get_post_format() );
endwhile;
 endif;
?>
 </div>

I have tried looking at so many tutorials and other people having similar problems but nothing seems to be working. 我尝试查看了许多教程以及其他有类似问题的人,但似乎没有任何效果。

The page is showing 10 posts because of the loop but its just adds the 10 and does not "scroll" 由于循环,该页面显示了10个帖子,但它仅添加了10个帖子,并不“滚动”

Getting this fixed would really help my stress levels! 解决这个问题确实可以帮助我缓解压力!

Solved it. 解决了。 I had to make Jetpack allow the infinite scroll to be used on Custom fields and pages. 我必须让Jetpack允许在“自定义”字段和页面上使用无限滚动。 By default it only works on the original posts page. 默认情况下,它仅适用于原始帖子页面。

Functions file: 功能文件:

function tweakjp_custom_is_support() {
return true;
$supported = current_theme_supports( 'infinite-scroll' ) && ( is_home() ||      is_archive() || is_front_page() );

return $supported;
}
  add_filter( 'infinite_scroll_archive_supported',      'tweakjp_custom_is_support' );

 function mm_infinite_scroll_render() {
    while ( have_posts() ) : the_post();
        get_template_part( 'content' );
    endwhile;
 }

  function mm_infinite_scroll_query_args($args) {

$new_args = array(
    'posts_per_page'   => $args['posts_per_page'],
    'paged'   => $args['paged'],
    'orderby'          => 'date',
    'order'            => 'DESC',
    'post_type'        => 'post',
    'post_status'      => 'publish',
);

return $new_args;
}

function mm_infinite_scroll_posts_where($clause) {
return "";
}

add_filter( 'infinite_scroll_posts_where', 'mm_infinite_scroll_posts_where' );

add_filter( 'infinite_scroll_query_args', 'mm_infinite_scroll_query_args',  9999 );
add_theme_support( 'infinite-scroll', array(
'container' => 'main-content',
'render' => 'mm_infinite_scroll_render'
) );

Then the content.php file has the rendering code. 然后content.php文件具有呈现代码。 Mine looks like this to help those who are unsure. 我的模样可以帮助那些不确定的人。

<div class="news-list">
<ul class="promo-list-items">
    <?php
    // Fetch all posts relating to a certain tag then display 4 of them
    //Get the Thumbnail URL
    $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 720,405 ), false, '' );
    ?>
    <div id="promolink"></div><li class="news-list-item" style="background-image: url(' <?php echo $src[0];?> '); background-repeat: no-repeat; background-size: cover;"> <a class="gdbnewslink" href="<?php echo get_permalink();?>" >
            <?php the_title();?>
        </a>
        <?php wp_reset_postdata(); ?>
    </li>
    <div class="clear"></div>
</ul>
</div>

Hope this helps someone with the same problem as me. 希望这对与我有同样问题的人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM