Ajax Load More

25.05.2021

Repeater Templates

<article id="post-<?php the_ID(); ?>" <?php post_class('post-archive'); ?>>
  <?php if (has_post_thumbnail()) { ?>
    <a href="<?php echo get_the_permalink(); ?>" class="post-thumbnail">
      <?php the_post_thumbnail( 'thumb-archive' ); ?>
    </a>
  <?php } ?>
  <div class="post-category">
    <?php $links = array_map( function ( $category ) {
      return sprintf(
        '<a href="%s" class="post-category_link">%s</a>',
        esc_url( get_category_link( $category ) ),
        esc_html( $category->name )
      );
    }, get_the_category() );

    echo implode( ' | ', $links ); ?>
  </div>
  <a href="<?php echo get_the_permalink(); ?>" class="post-title"><?php the_title(); ?></a>
  <span class="post-date"><?php the_time('M d, Y'); ?></span>
  <div class="post-excerpt"><?php the_excerpt(); ?></div>
  <a class="post-link" href="<?php echo get_the_permalink(); ?>"><?php _e( 'Read more', 'pcg' ); ?></a>
</article>

index.php

<?php 
// https://connekthq.com/plugins/ajax-load-more/examples/search-results/#code
if (is_search()) {
  $term = sanitize_text_field($_GET['s']);
  $label = __("Load more", "pcg");
  echo do_shortcode('[ajax_load_more container_type="div" post_type="post" sticky_posts="true" posts_per_page="3" offset="0" scroll="false" transition_container="false" button_label="' . $label . '" search="'. $term .'" orderby="relevance"]');
} else {
  $label = __("Load more", "pcg");
  echo do_shortcode('[ajax_load_more container_type="div" post_type="post" sticky_posts="true" posts_per_page="3" offset="0" scroll="false" transition_container="false" button_label="' . $label . '" archive="true"]');
}
?>

home.php

<?php
$label = __("Load more", "pcg");
echo do_shortcode('[ajax_load_more container_type="div" post_type="post" sticky_posts="true" posts_per_page="3" offset="0" scroll="false" transition_container="false" button_label="' . $label . '"]');
?>

Рекомендую к прочтению:

Оставить комментарий