ThemeShaper Forums » Thematic

[closed]

Enclosing Excerpt in Paragraph tag & adding a custom Read more Link

(18 posts)
  • Started 4 years ago by Tomakun
  • Latest reply from simonafilote
  • This topic is resolved
  1. Dear all, I've spent the day on this issue, trying things and browsing the forum. I'm desperate.

    I did this, to get excerpts displayed on my index page as well:

    function my_content($content) {
    	if (is_home() || is_front_page()) {
    	$content = 'excerpt';}
    	return $content;
    	}
    add_filter('thematic_content','my_content');

    Which seems to be working, however every html in it is stripped, but I would like to have a paragraph tag enclosing this.

    Now, I've tried to replace the return line from the above code with
    return '<p>' . $content . '</p>';

    as explained in the tutorial but when I do this, it returns me the full content...

    How can I enclose my excerpts with a simple <p> tag ?

    - - - - - - - - -

    I was also wondering how to add a custom Read more permalinks to all excerpts.

    The reason I want to ADD and not replace, is that we have 3 different types of behaviour for those. There is:

    1) the excerpt that's displayed using a Read more tag in your post body
    2) the automatic excerpt (the one limited to 55 characters by default).
    3) the custom excerpt

    Each one of these have a different behaviour when it comes to the "more link" and actually, when using the custom excerpt, you don't get any "more link" at all. Dealing with those at the same time was a pain to me. I couldn't figure it out and that's why I'm thinking that getting rid of all defaults Read more links and adding them "by hand" might be an easier, more consistent solution.

    Please can anyone put me in the right direction, those 2 issues are the last ones before my theme is finished. Thanks much for your help.

    Posted 4 years ago #
  2. About the Enclosing paragraph for Excerpt, this did it:

    function enclosing_p($post) {
    	if (is_single()) {
    	return $post;
    	} else {
    	return '<p>' . $post . '</p>';}
    }
    add_filter('thematic_post','enclosing_p');

    Basically I'm telling thematic to enclose the post with paragraphs in all pages except the Single Article one, because it return an empty </p> at the beginning anyway.

    Now if anybody could help me on adding those read more permalinks, that would be awesome.

    Posted 4 years ago #
  3. Caramboo
    Member

    I've also being trying to sort out my excerpts today. I came up with this for the Read More conundrum:

    function mytheme_excerpt($post) {
    	if(is_archive()) {
    		$post =  get_the_excerpt() . '<p class="excerpt_p">' .
                    '<a href=' . get_permalink() . '>Read More...' . '</a>';
    	}
    	return $post;
    }
    add_filter('thematic_post', 'mytheme_excerpt');

    It seems to work for custom excerpts and automatic ones. I styled the excerpt_p to give a bit of white space above it.

    Posted 4 years ago #
  4. Working here too! Thanks sooo much for sharing man, made my day! ^^

    Issue solved.

    Posted 4 years ago #
  5. I've found some errors in that code!
    There seems to be no closing-tag for the Paragraph and such things.

    I now use

    function mytheme_excerpt($post) {
    if(is_archive()||is_search()) {
    $post = '<p class="excerpt">' . get_the_excerpt() . ' ' . __('<!--:de-->weiterlesen<!--:--><!--:en-->read more<!--:-->') . ' »</p>';
    }
    return $post;
    }
    add_filter('thematic_post', 'mytheme_excerpt');

    I use __('<!--:de-->weiterlesen<!--:--><!--:en-->read more<!--:-->') for the Link because i have qTranslate on my blog. You can change it of course.

    Posted 4 years ago #
  6. Yes, actually it was right without the markup, I had defined my <p> tags in another function. Thanks for your feedback.

    Posted 4 years ago #
  7. i know this is an old post, but it comes up when searching for stuff on excerpts so i thought i'd through this in for anyone else looking. somewhere i found a post by chris and it solved my issue of not getting a 'read more' type of link on every excerpt (manual and auto). i changed the Read more text to continue reading and wrapped the excerpt in a paragraph.

    // excerpt read more links and wrap excerpt in p tag
    function all_excerpts_get_more_link($post_excerpt) {
    	return '<p>' . $post_excerpt . '</p>' . '<p class="readmore"><a href="'. get_permalink($post->ID) . '">' . 'Continue Reading &raquo' . '</a></p>';
    }
    add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link');
    Posted 4 years ago #
  8. Thanks Everyone! Helga, I've used your nice trim code and it works like a charm.
    Much appreciated yet again!

    Posted 4 years ago #
  9. Caramboo
    Member

    I just wanted to customise excepts and found my old (and now corrected).

    I used your method @helgatheviking but you missed off the semi-colon here:

    'Continue Reading &raquo;'

    Just in case anyone stumbles in here.

    Posted 4 years ago #
  10. slobjones
    Member

    Helga, would you edit your script so it does NOT wrap the excerpt in paragraph tags? The paragraph tags are unnecessary for my purposes and causing validation errors as well.

    I'd like to use the excerpt read more portion of the script, but I'm not so great at editing functions.php code.

    Thanks!

    Posted 3 years ago #
  11. umm did you even try? b/c well... not wrapping the excerpt in paragraph tags is as simple as NOT wrapping the excerpt in paragraph tags.

    // excerpt read more links and wrap excerpt in p tag
    function all_excerpts_get_more_link($post_excerpt) {
    	return $post_excerpt . '<p class="readmore"><a href="'. get_permalink($post->ID) . '">' . 'Continue Reading &raquo' . '</a></p>';
    }
    add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link');
    Posted 3 years ago #
  12. Hi Helga

    I've used the latest code you shared above to add the read more tag on category archive pages (on my blog menu items take you to category pages) and it worked fine. However, I would like to display the more link in the same style I did on the blog homepage (crumbs-of-life.net), where I used an image, but can't figure out how to do that.
    I used CSS to style the read more tag on the homepage:

    .post a.more-link {
        background: url("images/read-more.png") no-repeat scroll 3px 10px transparent !important;
        color: #E9E9E9 !important;
        display: block;
        float: right;
        font-size: 0;
        font-weight: 700;
        margin-right: 5px;
        margin-top: 25px;
        overflow: hidden;
        padding: 25px 59px;
        text-decoration: none;
    }

    I would very much appreciate your advice on this.

    Posted 2 years ago #
  13. if you are referring to the post directly above yours... then the a link has no .more-link class, so your style would never get applied. just add your class to the link.

    Posted 2 years ago #
  14. Thanks for your response, Helga.

    Indeed, I was referring to the post directly above mine. And I think I understand what yoú're saying, but I don't know exactly how to do that. I've only used the a.more-link code from someone else and don't really know how to work with classes.

    Should I modify your code like this? Hm, it doesn't look right :) Can you please help me out a bit?

    // excerpt read more links and wrap excerpt in p tag
    function all_excerpts_get_more_link($post_excerpt) {
    	return $post_excerpt . '<p class="readmore"><a>ID) . '">' . 'a.more-link' . '</a></p>';
    }
    add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link');
    Posted 2 years ago #
  15. your code is wrong and will cause your links to look like:
    ID)">a.more-link
    if it doesn't cause a parse error

    a.more-link means the A element has a class="more-link"

    // excerpt read more links and wrap excerpt in p tag
    function all_excerpts_get_more_link($post_excerpt) {
    	return $post_excerpt . '<p class="readmore"><a class="more-link" href="'. get_permalink($post->ID) . '">' . 'Continue Reading &raquo' . '</a></p>';
    }
    add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link');

    btw- code goes between backticks ` and not apostrophes '.

    Posted 2 years ago #
  16. Thanks so much for this Helga, now I see how this works...

    One final question, what bit of code should I remove from here to avoid the more link+image to go one line lower?

    Posted 2 years ago #
  17. i presume you mean you don't want it to be a paragraph. remove the paragraph tags that surround the link.

    Posted 2 years ago #
  18. yes! I made it :) thanks again for all the help Helga.

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.