2014-09-22 3 views
0

Я пытаюсь получить бесконечный прокрутки для работы, но, похоже, не может заставить его работать.Jetpack Infinite Scroll не работает

У меня есть три файла пост цикла content-post-ft.php, the functions.php, а затем моя первая страница, где посты загружаются frontpage.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'); 
    } 

контента после 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

<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> 

Я пытался смотреть на так много учебников и других людей, имеющих схожие проблемы, но ничего, кажется, работает.

страница показывает 10 сообщений из-за цикл, но его просто добавляет 10 и не «прокручивать»

Как это установило действительно поможет моему уровню стресса!

+0

Вы пробовали искать в [консоли браузеров] (https://developer.mozilla.org/en-US/docs/Tools/Web_Console)? Любые ошибки? – max

+0

Нет ошибок, которые я вижу. Страница просто не хочет использовать бесконечный свиток по какой-либо причине. У меня также есть проверка на странице, чтобы убедиться, что она работает, и она есть. Просто что-то мешает ему работать, и я понятия не имею, что. – Kyon147

ответ

0

Решено. Я должен был заставить Jetpack использовать бесконечный прокрутки для пользовательских полей и страниц. По умолчанию он работает только на исходной странице сообщений.

Функции файла:

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' 
)); 

Затем файл content.php имеет код рендеринга. Моя выглядит так, чтобы помочь тем, кто не уверен.

<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> 

Надеюсь, это поможет кому-то с той же проблемой, что и я.

Смежные вопросы