Support » Fixing WordPress » Excerpt more link to category not single page

  • Resolved Calicosun

    (@calicosun)


    Hi

    Is anyone able to tell me how I can get the more link in the excerpt to link through to the posts pages not the single page?

    I have a category called Testimonials and want to display an excerpt of random testimonials on the home page in the sidebar with a read more that links back to the Testimonials post page where ALL the testimonials are. Currently the read more link takes you to a single page of the excerpt.

    My code is as follows (sorry not sure why wont go in code box):

    `<?php
    $posts = get_posts(‘category_name=Testimonials&numberposts=1&orderby=rand’);
    foreach ($posts as $post) : start_wp(); ?>

    <h2><?php the_title(); ?></h2>

    <?php the_excerpt(); ?>
    <?php
    endforeach;
    ?>;`

    and the function is:

    <?php
    
    function remove_more_jump_link($link) {
    $offset = strpos($link, '#more-');
    if ($offset) {
    $end = strpos($link, '"',$offset);
    }
    if ($end) {
    $link = substr_replace($link, '', $offset, $end-$offset);
    }
    return $link;
    }
    add_filter('the_content_more_link', 'remove_more_jump_link');
    
    function excerpt_ellipse($text) {
       return str_replace('[...]', ' <a href="'.get_permalink().'"> more...</a>', $text); }
    add_filter('the_excerpt', 'excerpt_ellipse');
    
    ?>

    Please note that I have other read mores that should link to the single page.

    Thank you so much.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Just wondering if anyone might be able to help me out here? I have looked and looked but can’t seem to be able to figure it out myself. Still learning php.

    Thanks so much!

    Hi there

    Is the reason no one has been able to help me because I have not provided enough information? If so let me know what else you need.

    If it is because this is not possible or too complex to explain please let me know.

    Thank you.

    Michael

    (@alchymyth)

    Forum Moderator

    this might work with wp2.9 and higher:
    http://codex.wordpress.org/Template_Tags/the_excerpt#Remove_.5B….5D_string_using_Filters

    it will take only the first category of the possible many categories of the post, and link to it.

    function new_excerpt_more($more) {
    $ct=get_the_category($post->ID); $ct = $ct[0]->cat_ID;
    return '<a href="'. get_category_link($ct) . '"> more ...</a>';
    }
    add_filter('excerpt_more', 'new_excerpt_more');

    (hopefully it does not interfere with this existing filter

    function excerpt_ellipse($text) {
       return str_replace('[...]', ' <a href="'.get_permalink().'"> more...</a>', $text); }
    add_filter('the_excerpt', 'excerpt_ellipse');

    )

    Thank you so much for your help. This has worked perfectly. I appreciate you taking the time to help me out.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Excerpt more link to category not single page’ is closed to new replies.