• Hi, for some reason, the ‘more’ link at the end of the excerpt is not present in the blog posts that are loaded with the AJAX Load More button.

    I have this code in the content-grid loop as follows:

    <div class="entry-content-grid">
        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
           <?php
                  if ( has_post_thumbnail( ) ) { // check if the post has a Post Thumbnail assigned to it.
                  echo '<a class="entry-thumb" href="'.get_permalink($post->ID).'">';
               //   echo the_post_thumbnail(array(293,275));  orig
    			   echo the_post_thumbnail();    
    			  
                      echo '</a>';
                  } ?>
           <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'adapt' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    
    <div class="post-excerpt">
          <?php if ( comments_open() && ! post_password_required() ) : ?>
          <?php endif; ?>
                       
          <?php echo excerpt(17);
          	//the_excerpt(); ?>
           <?php echo '<a class="read-more" href="'.get_permalink($post->ID).'"><em>More...</em></a>'; ?>
    
          <?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'adapt' ) . '</span>', 'after' => '</div>' ) ); ?>
    </div><!-- .post-excerpt -->
    <footer> </footer>
    </article><!-- #post-<?php the_ID(); ?> -->
    </div><!-- .entry-content-grid -->

    Do you know how I can fix this so it’s consistent?

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

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Darren Cooney

    (@dcooney)

    Hi @ddpweb,
    Not sure why that’s happening.

    Can you try writing it like:
    <p><a class="read-more" href="<?php the_permalink();?>"><em>More...</em></a></p>

    vs:
    <?php echo '<a class="read-more" href="'.get_permalink($post->ID).'"><em>More...</em></a>'; ?>

    Dont see why that would be any different, but I have no idea ??

    Thread Starter ddpweb

    (@ddpweb)

    Thank you for the reply. I tried this modification, but it’s doing the same thing.

    I’ve had a lot of issues with this Load More button. Something is stripping things out.
    I’ve been able to resolve all but two things.

    1. The More link doesn’t render inside that ‘more’ loop
    and
    2. The custom excerpt is also not respected

    Is there any insight you could share about this? Client is super picky about things being consistent.

    Thread Starter ddpweb

    (@ddpweb)

    Here is the code I’m using for the button

     <?php get_template_part( 'content-grid', get_post_format() ); ?>  
    <?php
      
       endwhile; wp_reset_query();
       
       // Ajax Load More
       $post__not_in = '';
       if($do_not_duplicate){
          $post__not_in = implode(',', $do_not_duplicate); 
       } 
       echo do_shortcode('[ajax_load_more  post__not_in="'.$post__not_in.'" container_type="div" post_type="post" posts_per_page="24" pause="true" transition="fade" scroll="false" images_loaded="true"  offset="1" button_label="Load More"]');
            
       ?>     
            

    Here’s the code I’m using for the custom excerpt on functions.php

    /**
     * Sets custom excerpt length. 
    */
    
    function excerpt($limit) {
      $excerpt = explode(' ', get_the_excerpt(), $limit);
      if (count($excerpt)>=$limit) {
        array_pop($excerpt);
        $excerpt = implode(" ",$excerpt).'...';
      } else {
        $excerpt = implode(" ",$excerpt);
      }	
      $excerpt = preg_replace('<code>[[^]]*]</code>','',$excerpt);
      return $excerpt;
    }
     
    function content($limit) {
      $content = explode(' ', get_the_content(), $limit);
      if (count($content)>=$limit) {
        array_pop($content);
        $content = implode(" ",$content).'...';
      } else {
        $content = implode(" ",$content);
      }	
      $content = preg_replace('/[.+]/','', $content);
      $content = apply_filters('the_content', $content); 
      $content = str_replace(']]>', ']]>', $content);
      return $content;
    }
    
    /* Now, in every place where you use the_excerpt() or the_content() in your loop, use excerpt($limit) or content($limit).  eg echo excerpt(30)*/
    Thread Starter ddpweb

    (@ddpweb)

    Do I need to add something to the Load More button syntax to make the excerpt be consistent?

    Plugin Author Darren Cooney

    (@dcooney)

    Really not sure… I use the same excerpt($limit) function on my site and it works as expected.

    If
    <p><a class="read-more" href="<?php the_permalink();?>"><em>More...</em></a></p>
    is not showing are you sure you’re editing the correct repeater template?

    • This reply was modified 6 years, 7 months ago by Darren Cooney.
    Thread Starter ddpweb

    (@ddpweb)

    ok, it’s a mystery then.

    I’m only using one content template for that loop. It feeds the following page and archive templates.

    This is my repeater loop: content-grid.php

    and the syntax for it as at the top of this thread.

    I’m feeding this into:

    archive.php
    category.php
    page-on-the-wall.php

    Using the same AJAX Load button code for each. And the same loop syntax.

    I really appreciate your responses man.

    I guess I have to start pulling things apart until I find where the conflict is.

    Thread Starter ddpweb

    (@ddpweb)

    Hi @dcooney,

    Ok, I’ve figured this out, kind of. It seems that the code I have in the functions.php file that dynamically truncates the excerpt with the … and ‘more’ link works more consistenly than having that more link in the content-grid loop. For what ever reason.

    But it does not play nice with the custom excerpt length. So I had to revert back to the standard ‘excerpt’ syntax and rely on that field override for each post.

    I had this code commented out on the live site, and was using the link in the loop instead with the custom length of the excerpt. But turing this on and commenting that link out of the loop makes it more consistent.

    It’s on the staging site now for the client to review. Hopefully they’ll just approve this, and I’ll migrate that change over.

    Just wanted you to know.

    /** ====================================================
     * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and adapt_continue_reading_link().
     *
     * To override this in a child theme, remove the filter and add your own
     * function tied to the excerpt_more filter hook.
    
     */
    
    function adapt_auto_excerpt_more( $more ) {
    	return ' &hellip;' . adapt_continue_reading_link();
    }
    add_filter( 'excerpt_more', 'adapt_auto_excerpt_more' );
    
    /** * Returns a "Continue Reading" link for excerpts - works with function below */
    
    function adapt_continue_reading_link() {
    	return ' <a class="read-more" href="'. esc_url( get_permalink() ) . '">' . __( '<em>More</em>', 'adapt' ) . '</a>';
    }
    
    /** * Adds a pretty "More" link to custom post excerpts.
     *
     * To override this link in a child theme, remove the filter and add your own
     * function tied to the get_the_excerpt filter hook.
     */ 
    
    function adapt_custom_excerpt_more( $output ) {
    	if ( has_excerpt() && ! is_attachment() ) {
    		$output .= adapt_continue_reading_link();
    	}
    	return $output;
    }
    add_filter( 'get_the_excerpt', 'adapt_custom_excerpt_more' );
    //==================================================== */
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Read More link at end of excerpt is not loading inside of the Load More’ is closed to new replies.