Support » Plugin: WordPress Infinite Scroll - Ajax Load More » All read more links point to the same page

  • Resolved Tim Derouin

    (@tderouindesign)


    Hello,

    We recently realized that when clicking the load more button under our four featured Press posts, the four new posts all link to the page you are already on. The four posts that display after clicking Load More consist of a description, title, date and Read More button. The titles and read more buttons all link to the page the user is already on.

    I have updated the plugin and created a new shortcode with no luck.

    I am not the original developer and believe the problem is with the query they setup some time ago but wanted to reach out to the plugin developer in case you are aware of this issue and have a solution.

    Apologies if this has been answered already in this support forum, I could not find anything specific to what the glitch we are having. TIA!

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author dcooney

    (@dcooney)

    @tderouindesign Can you share the Repeater Template please?
    It could a global $post issue.

    https://connekthq.com/plugins/ajax-load-more/docs/repeater-templates/

    Thread Starter Tim Derouin

    (@tderouindesign)

    This is the current default repeater template

    <?php
    session_start();
    $post_id = get_the_ID();
    if(in_category(4, $post_id)) {
    $permalink = get_field(‘link’, $post_id);
    } else {
    $permalink = get_permalink($post_id);
    }

    if($load_more_count == 0 && $_SESSION[‘page’] != ‘event’ && $_SESSION[‘page’] != ‘virtualvigil’) {
    echo ‘<div class=”row”>’ . “\n”;
    }

    if($_SESSION[‘page’] == ‘press’) {
    $count_end = 3;
    $count_end_total = 3;
    $date = strtotime(get_the_date());
    if(in_category(4, $post_id)) {
    $permalink = get_field(‘link’, $post_id);
    } else {
    $permalink = get_permalink($post_id);
    }

    $title = get_the_title($post_id);
    $img = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), ‘thumb’);

    echo ‘<div class=”col-12 col-md-6 col-lg-3 mb-3″>’;
    echo ‘<div class=”post press”><div class=”thumbnail’;
    if(!isset($img[0])) {
    echo ‘ default”>’;
    } else {
    echo ‘” style=”background-image: url(\” . $img[0] . ‘\’);”>’;
    }
    echo ‘</div>
    <p class=”entry-title mt-4 mb-0″>‘ . $title . ‘</p>’;
    echo ‘<p class=”date mt-2 mb-2″>’ . date(‘n/j/y’, $date) . ‘</p>’;
    echo ‘</div></div>’;
    if($load_more_count == $count_end || $load_more_count_total == $count_end_total) {
    echo ‘</div>’ . “\n” . ‘ <!– end .row –>’; // end .row
    $load_more_count = -1;
    }
    } elseif($_SESSION[‘page’] == ‘media’) {
    $count_end_total = 6;
    $permalink = get_field(‘link’, $post_id);
    echo ‘<div class=”col-12 col-lg-6 post media-mention mb-4″>’ . “\n”;
    echo ‘<p class=”excerpt mb-0″>’ . get_the_excerpt() . ‘</p>’ . “\n”;
    echo ‘<p class=”title mb-0″>‘ . get_the_title() . ‘</p>’ . “\n”;
    echo ‘<p class=”date”>’ . date(‘n/j/y’, strtotime(get_the_date())) . ‘</p>’ . “\n”;
    echo ‘Read more‘ . “\n”;
    echo ‘</div>’ . “\n”;
    if($load_more_count_total == $count_end_total) {
    echo ‘</div>’ . “\n” . ‘ <!– end .row –>’; // end .row
    }
    } elseif($_SESSION[‘page’] == ‘event’) {
    $event = get_post($post_id);
    $event_date = get_field(‘event_date’, $post_id);
    $now = new DateTime();
    $now_plus_1 = new DateTime(date(‘F j, Y’, strtotime(‘+1 day’, time()))); // add a day
    $event_date_time = new DateTime($event_date);
    echo ‘<div class=”row event”>’ . “\n”;
    echo ‘<div class=”col-lg-4″>’ . “\n”;
    echo ‘<p class=”date”>’ . $event_date . ‘</p>’ . “\n”;
    echo ‘<p class=”time”>’ . get_field(‘event_time’, $post_id) . ‘</p>’ . “\n”;
    if($now_plus_1 > $event_date_time) {
    echo ‘<span class=”past”>PAST</span>’ . “\n”;
    }
    $flyer = get_field(‘flyer’, $post_id);
    if(is_array($flyer)) {
    echo ‘Download Flyer‘ . “\n”;
    }
    echo ‘</div>’ . “\n”;
    echo ‘<div class=”col-lg-8 details”>’ . “\n”;
    echo $event->post_content . “\n”;
    echo ‘</div>’ . “\n”;
    echo ‘</div>’ . “\n”;
    echo ‘<hr>’;
    } elseif($_SESSION[‘page’] == ‘virtualvigil’) {
    $post_name = get_the_title($post_id);
    $post_content = get_the_content($post_id);
    $post_country = get_field(‘country’, $post_id);
    $photo = wp_get_attachment_image_src(get_post_thumbnail_id(), ‘full’);
    echo ‘<div class=”col-12 col-lg-6 mb-4″>’;
    echo ‘‘;
    echo ‘<div class=”background” style=”background-image: url(\” . $photo[0] . ‘\’);”></div>’ . “\n”;
    echo ‘<p class=”author”>‘ . $post_name . ‘, <span>’ . $post_country . ‘</span></p>’;
    echo ‘<div class=”caption”>’ . nl2br(strip_tags($post_content)) . ‘</div>’ . “\n”;
    echo ‘
    ‘ . “\n”;
    echo ‘</div>’ . “\n”;
    } else {
    if($load_more_count == 0) {
    echo ‘<div class=”row”>’ . “\n”;
    }
    $count_end = 2;
    $count_end_total = 5;
    ?>
    <article class=”post col-12 col-lg-4″ id=”post-4″ <?php post_class(); ?>>
    <header class=”entry-header”>
    “>
    <?php
    if(has_post_thumbnail()) {
    echo ‘<div class=”thumbnail” style=”background-image: url(\” . get_the_post_thumbnail_url(get_the_ID(), ‘original’) . ‘\’);”></div>’;
    } else {
    echo ‘<div class=”thumbnail default”></div>’;
    }
    ?>


    <?php
    //kpn_post_thumbnail();
    the_title( ‘<h2 class=”entry-title mt-4″>‘, ‘</h2>’ );

    if ( ‘post’ === get_post_type() ) :
    ?>
    <div class=”entry-meta”>
    <p class=”date”><?php echo date(‘n/j/y’, strtotime(get_the_date())); ?></p>
    </div><!– .entry-meta –>
    <?php endif; ?>
    </header><!– .entry-header –>

    <div class=”entry-content”>
    <?php
    the_excerpt();
    ?>
    </div><!– .entry-content –>
    </article><!– #post-<?php the_ID(); ?> –>
    <?php
    if($load_more_count == $count_end || $load_more_count_total == $count_end_total) {
    echo ‘</div>’ . “\n” . ‘ <!– end .row –>’; // end .row
    $load_more_count = -1;
    }
    }
    $load_more_count++;
    $load_more_count_total++;
    ?>

    Thread Starter Tim Derouin

    (@tderouindesign)

    This is the code specific to the problematic page:

    <div class=”container”>
    <header class=”hero”>
    <?php kpn_post_thumbnail(); ?>
    <div class=”title”><?php the_title( ‘<h1 class=”entry-title”>’, ‘</h1>’ ); ?></div>
    </header><!– .entry-header –>
    <div class=”row mt-5″>
    <div class=”col”>
    <h2 class=”mb-0″>Press Releases</h2>
    </div>
    </div>
    <div class=”row mt-5 mb-3″>
    <?php
    $latest_posts = get_posts(array(
    ‘numberposts’ => 4,
    ‘category’ => 2
    ));

    foreach($latest_posts as $key => $post) {
    $post_id = $post->ID;

    $date = strtotime($post->post_date);
    if(in_category(4, $post_id)) {
    $permalink = get_field(‘link’, $post_id);
    } else {
    $permalink = get_permalink($post_id);
    }

    $title = get_the_title($post_id);
    $img = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), ‘thumb’);

    echo ‘<div class=”col-12 col-md-6 col-lg-3″>’;
    echo ‘<div class=”post press”><div class=”thumbnail’;
    if(!isset($img[0])) {
    echo ‘ default”>’;
    } else {
    echo ‘” style=”background-image: url(\” . $img[0] . ‘\’);”>’;
    }
    echo ‘</div>
    <p class=”entry-title mt-4 mb-0″>‘ . $title . ‘</p>’;
    echo ‘<p class=”date mt-2 mb-2″>’ . date(‘n/j/y’, $date) . ‘</p>’;
    //echo ‘<div class=”excerpt”>’ . get_the_excerpt($post_id) . ‘</div>’;
    //echo ‘Read more‘;
    echo ‘</div></div>’;
    }
    wp_reset_query();
    ?>
    </div>
    <div class=”row”>
    <div class=”col”>
    <?php
    $_SESSION[‘page’] = ‘media’;
    echo do_shortcode(‘[ajax_load_more posts_per_page=”4″ category=”press” offset=”4″ pause=”true” scroll=”false” button_label=”Load More”]’);
    ?>
    </div>
    </div>
    <div class=”row mt-5 mb-5″>
    <div class=”col”>
    <h2 class=”mb-0″>Media Mentions</h2>
    </div>
    </div>
    <div class=”row”>
    <div class=”col-12″>
    <div class=”row”>
    <?php
    $media_posts = get_posts(array(
    ‘numberposts’ => 6,
    ‘category’ => 6
    ));

    foreach($media_posts as $key => $post) {
    $post_id = $post->ID;
    $permalink = get_field(‘link’, $post_id);
    echo ‘<div class=”col-12 col-lg-6 post media-mention mb-4″>’ . “\n”;
    echo ‘<p class=”excerpt mb-0″>’ . $post->post_excerpt . ‘</p>’ . “\n”;
    echo ‘<p class=”title mb-0″>‘ . $post->post_title . ‘</p>’ . “\n”;
    echo ‘<p class=”date”>’ . date(‘n/j/y’, strtotime($post->post_date)) . ‘</p>’ . “\n”;
    echo ‘Read more‘ . “\n”;
    echo ‘</div>’ . “\n”;
    }
    wp_reset_query();
    ?>
    </div>
    <div class=”row”>
    <div class=”col”>
    <?php
    $_SESSION[‘page’] = ‘media’;
    echo do_shortcode(‘[ajax_load_more posts_per_page=”6″ category=”media” offset=”6″ pause=”true” scroll=”false” button_label=”Load More”]’);
    ?>
    </div>
    </div>
    </div>
    </div>
    <div class=”row”>
    <div class=”col”>
    <?php the_content(); ?>
    </div>
    </div>
    </div><!– .container –>

    Plugin Author dcooney

    (@dcooney)

    Thread Starter Tim Derouin

    (@tderouindesign)

    I can’t find reference to any other “repeater template code” besides the default code and the page code shared. I did not setup the website but have been tasked with maintaining it. Apologies for my confusion. I do not have the custom repeaters add on, do I need that? Thank you for your time and patience!

    Plugin Author dcooney

    (@dcooney)

    Under Ajax Load More > Repeater Templates in WP admin.

    Thread Starter Tim Derouin

    (@tderouindesign)

    All that is listed there is what I first shared for the Default Template code:

    <?php
    session_start();
    $post_id = get_the_ID();
    if(in_category(4, $post_id)) {
    $permalink = get_field(‘link’, $post_id);
    } else {
    $permalink = get_permalink($post_id);
    }

    if($load_more_count == 0 && $_SESSION[‘page’] != ‘event’ && $_SESSION[‘page’] != ‘virtualvigil’) {
    echo ‘<div class=”row”>’ . “\n”;
    }

    if($_SESSION[‘page’] == ‘press’) {
    $count_end = 3;
    $count_end_total = 3;
    $date = strtotime(get_the_date());
    if(in_category(4, $post_id)) {
    $permalink = get_field(‘link’, $post_id);
    } else {
    $permalink = get_permalink($post_id);
    }

    $title = get_the_title($post_id);
    $img = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), ‘thumb’);

    echo ‘<div class=”col-12 col-md-6 col-lg-3 mb-3″>’;
    echo ‘<div class=”post press”><div class=”thumbnail’;
    if(!isset($img[0])) {
    echo ‘ default”>’;
    } else {
    echo ‘” style=”background-image: url(\” . $img[0] . ‘\’);”>’;
    }
    echo ‘</div>
    <p class=”entry-title mt-4 mb-0″>‘ . $title . ‘</p>’;
    echo ‘<p class=”date mt-2 mb-2″>’ . date(‘n/j/y’, $date) . ‘</p>’;
    echo ‘</div></div>’;
    if($load_more_count == $count_end || $load_more_count_total == $count_end_total) {
    echo ‘</div>’ . “\n” . ‘ <!– end .row –>’; // end .row
    $load_more_count = -1;
    }
    } elseif($_SESSION[‘page’] == ‘media’) {
    $count_end_total = 6;
    $permalink = get_field(‘link’, $post_id);
    echo ‘<div class=”col-12 col-lg-6 post media-mention mb-4″>’ . “\n”;
    echo ‘<p class=”excerpt mb-0″>’ . get_the_excerpt() . ‘</p>’ . “\n”;
    echo ‘<p class=”title mb-0″>‘ . get_the_title() . ‘</p>’ . “\n”;
    echo ‘<p class=”date”>’ . date(‘n/j/y’, strtotime(get_the_date())) . ‘</p>’ . “\n”;
    echo ‘Read more‘ . “\n”;
    echo ‘</div>’ . “\n”;
    if($load_more_count_total == $count_end_total) {
    echo ‘</div>’ . “\n” . ‘ <!– end .row –>’; // end .row
    }
    } elseif($_SESSION[‘page’] == ‘event’) {
    $event = get_post($post_id);
    $event_date = get_field(‘event_date’, $post_id);
    $now = new DateTime();
    $now_plus_1 = new DateTime(date(‘F j, Y’, strtotime(‘+1 day’, time()))); // add a day
    $event_date_time = new DateTime($event_date);
    echo ‘<div class=”row event”>’ . “\n”;
    echo ‘<div class=”col-lg-4″>’ . “\n”;
    echo ‘<p class=”date”>’ . $event_date . ‘</p>’ . “\n”;
    echo ‘<p class=”time”>’ . get_field(‘event_time’, $post_id) . ‘</p>’ . “\n”;
    if($now_plus_1 > $event_date_time) {
    echo ‘<span class=”past”>PAST</span>’ . “\n”;
    }
    $flyer = get_field(‘flyer’, $post_id);
    if(is_array($flyer)) {
    echo ‘Download Flyer‘ . “\n”;
    }
    echo ‘</div>’ . “\n”;
    echo ‘<div class=”col-lg-8 details”>’ . “\n”;
    echo $event->post_content . “\n”;
    echo ‘</div>’ . “\n”;
    echo ‘</div>’ . “\n”;
    echo ‘<hr>’;
    } elseif($_SESSION[‘page’] == ‘virtualvigil’) {
    $post_name = get_the_title($post_id);
    $post_content = get_the_content($post_id);
    $post_country = get_field(‘country’, $post_id);
    $photo = wp_get_attachment_image_src(get_post_thumbnail_id(), ‘full’);
    echo ‘<div class=”col-12 col-lg-6 mb-4″>’;
    echo ‘‘;
    echo ‘<div class=”background” style=”background-image: url(\” . $photo[0] . ‘\’);”></div>’ . “\n”;
    echo ‘<p class=”author”>‘ . $post_name . ‘, <span>’ . $post_country . ‘</span></p>’;
    echo ‘<div class=”caption”>’ . nl2br(strip_tags($post_content)) . ‘</div>’ . “\n”;
    echo ‘
    ‘ . “\n”;
    echo ‘</div>’ . “\n”;
    } else {
    if($load_more_count == 0) {
    echo ‘<div class=”row”>’ . “\n”;
    }
    $count_end = 2;
    $count_end_total = 5;
    ?>
    <article class=”post col-12 col-lg-4″ id=”post-4″ <?php post_class(); ?>>
    <header class=”entry-header”>
    “>
    <?php
    if(has_post_thumbnail()) {
    echo ‘<div class=”thumbnail” style=”background-image: url(\” . get_the_post_thumbnail_url(get_the_ID(), ‘original’) . ‘\’);”></div>’;
    } else {
    echo ‘<div class=”thumbnail default”></div>’;
    }
    ?>


    <?php
    //kpn_post_thumbnail();
    the_title( ‘<h2 class=”entry-title mt-4″>‘, ‘</h2>’ );

    if ( ‘post’ === get_post_type() ) :
    ?>
    <div class=”entry-meta”>
    <p class=”date”><?php echo date(‘n/j/y’, strtotime(get_the_date())); ?></p>
    </div><!– .entry-meta –>
    <?php endif; ?>
    </header><!– .entry-header –>

    <div class=”entry-content”>
    <?php
    the_excerpt();
    ?>
    </div><!– .entry-content –>
    </article><!– #post-<?php the_ID(); ?> –>
    <?php
    if($load_more_count == $count_end || $load_more_count_total == $count_end_total) {
    echo ‘</div>’ . “\n” . ‘ <!– end .row –>’; // end .row
    $load_more_count = -1;
    }
    }
    $load_more_count++;
    $load_more_count_total++;
    ?>

    Plugin Author dcooney

    (@dcooney)

    Sorry, Im really not sure. This template is a disaster.

    I’d start by adding global $post; to the top of the template.
    And then trying to switch all get_the_ID with $post->ID;

    good luck.

    Thread Starter Tim Derouin

    (@tderouindesign)

    We can agree on that 100%!

    I appreciate your feedback and will start by adding what you have suggested.

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.