The MU forums have moved to WordPress.org

Site URL, changing the_excerpt tag and the Search page (3 posts)

  1. dleek
    Member
    Posted 14 years ago #

    I recently changed the_excerpt() tag using this function:

    function new_excerpt_more($text) {
       return str_replace('[...]', '[<a href="'. get_permalink($post->ID) . '">' . 'Read the rest of this entry &raquo;' . '</a>]', $text);
     }
     add_filter('the_excerpt', 'new_excerpt_more');

    This works great on my homepage, where I wanted users to be forced to read more. It directs them to the permalink for the post. What I did not realize, though, was that when I did this, my search page (also using the_excerpt, and using the One Search plugin to search all of my wpmu sites) makes the permalink in the excerpt think that it is associated with the main site when it should be another site.

    For example, if you go to my site at http://nccumc.org, and click "Read the rest of this entry" on any of the first posts with an image, you are directed to the correct permalink because they are assocaiated with the main site. But, if you search for something like this http://nccumc.org/?s=facebook, and you click the "Read the rest of this entry" on the first post, you will get a Page Not Found error. However, if you click the title, it works correctly since it pulls the permalink from The Loop. That link should be part of the "Children" site.

    Is there anyway I can dynamically get the real permalink for the post when changing the excerpt?

    Thanks for the help! Let me know if anyone needs anymore information.

  2. SteveAtty
    Member
    Posted 14 years ago #

  3. dleek
    Member
    Posted 14 years ago #

    Thanks SteveAtty! I was able to get it to work with that function. Here is what I ended up with:

    function new_excerpt_more($text) {
       global $post;
       return str_replace('[...]', '[<a href="'. get_blog_permalink( $post->blog_id, $post->ID ) . '">' . 'Read the rest of this entry &raquo;' . '</a>]', $text);
     }
     add_filter('the_excerpt', 'new_excerpt_more');

About this Topic