Visitor14
Visitor14

Reputation: 13

Excerpt "Read more>>" pointing to current URL

I have a custom page template set up to pull category post onto a "page" I've set up a function for the excerpt to display. "Read More>>" is present, however, the post id is not pulling in the permalink for the individual posts. The excerpt after each post links to this same page I created.

functions.php-->

function excerpt($num) {
 $limit = $num+1;
 $excerpt = explode(' ', get_the_excerpt(), $limit);
 array_pop($excerpt);
 $excerpt = implode(" ",$excerpt). ' <a href="' . get_permalink($post->ID) . '" class="more-link" title="Read More">Read More >></a>';
echo $excerpt;
}

function excerpt_length($length) {
  return 40;
}
add_filter('excerpt_length', 'excerpt_length');

content.php-->

<div class="entry-content">
<?php if ( is_category() || is_archive() || is_search() || is_home() ) {
        the_excerpt();
    } else {
        the_excerpt();
    } ?>
</div>

-------Another function I've been testing with similar results, which includes global $post.

 function themprefix_excerpt_read_more_link($output) {
   global $post;
 return $output . ' <a href="' . get_permalink($post->ID) . '" class="more-link" title="Read More">Read More >></a>';
}
 add_filter( 'the_excerpt', 'themprefix_excerpt_read_more_link' );

Custom page template -->

<?php get_header(); ?>
   <div id="main" class="row-fluid">
    <div id="main-left" class="span8">
        <?php while ( have_posts() ) : the_post(); ?>
        <?php get_template_part( 'content', 'page' ); ?>

            <?php
                $catPost = get_posts('cat=225&posts_per_page=3');
                foreach ($catPost as $post) : setup_postdata($post); 
            ?>

        <?php get_template_part('content'); ?>
        <?php endforeach;?>
        <?php comments_template( '', true ); ?>
        <?php endwhile; // end of the loop. ?>
    </div><!-- #main-left -->       
        <?php get_sidebar(); ?>
   <div class="clearfix"></div>
   </div><!-- #main -->
<?php get_footer(); ?>

Upvotes: 0

Views: 235

Answers (1)

Marin Atanasov
Marin Atanasov

Reputation: 3316

Try using global $post in the beginning of your excerpt() function.

Upvotes: 2

Related Questions