ThemeShaper Forums » Thematic

[closed]

Auto excerpt

(26 posts)
  • Started 3 years ago by qwik3r
  • Latest reply from helgatheviking
  • This topic is not resolved

Tags:

  1. qwik3r
    Member

    Themenatic is boggling my mind, at times I wonder if its easier just to code this stuff myself from scratch instead of scouring through functions that I don't even know where they are. Anyway, is there a way to do auto excerpt so that it truncates the content after a certain length with thematic?

    Posted 3 years ago #
  2. thematic is awesome, but there IS a definite learning curve. there is a post here on how to switch stuff over to excerpts:

    http://forums.themeshaper.com/topic/custom-excerpts#post-11213

    Posted 3 years ago #
  3. qwik3r
    Member

    I saw this post but its not quite what i was looking for as it relies then on manual excerpts which means I have to type up a separate description, I'd almost rather just have it truncate the main content after a certain character length and include a read more...

    Posted 3 years ago #
  4. get_the_excerpt does not 'rely' on manual excerpts, and I am fairly certain that IS what you are asking for. using gene's function you toggle thematic to use get_the_excerpt on the home (blog) page versus its initial behavior of get_the_content. i 'think' most of the other loops use get_the_excerpt by default. anyway, get_the_excerpt looks first to a manual excerpt and will use that where there is one. in the lack of a manual excerpt it will just take the first X many characters to make an excerpt automatically.

    here is all the code i use for excerpts:

    //use excerpts on home page
    function child_content($content) {
    	if ( is_home() ) {
    		$content = 'excerpt';
    	}
    return $content;
    }
    add_filter('thematic_content', 'child_content');
    
    // excerpt read more links- adds a read more link to every excerpt- including manual ones
    function all_excerpts_get_more_link($post_excerpt) {
    
    	return $post_excerpt . '<span class="readmore"><a href="'. get_permalink($post->ID) . '">' . 'Read More' . '</a></span>';
    }
    add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link');
    
    // change [...] to ... or whatever
    function excerpt_ellipse($text) {
       return str_replace('[...]', '...', $text);
       }
    add_filter('get_the_excerpt', 'excerpt_ellipse');
    
    //change length of excerpt
    function new_excerpt_length($length) {
    return 20;
    }
    add_filter('excerpt_length', 'new_excerpt_length');
    Posted 3 years ago #
  5. brixon
    Member

    this is excellent. many thanks :)

    Posted 3 years ago #
  6. dont forget to mark the topic resolved if this solved your issues

    Posted 3 years ago #
  7. brixon
    Member

    hmm- is it still possible to load an image or youtube link in this excerpt?

    Posted 3 years ago #
  8. i guess one of the easiest ways would be to put it in this function somewhere. notice that the span tags and a link come after the excerpt. i've posted in another thread this is also a good place to add a thumbnail.

    // excerpt read more links- adds a read more link to every excerpt- including manual ones
    function all_excerpts_get_more_link($post_excerpt) {
    
    	return $post_excerpt . '<span class="readmore"><a href="'. get_permalink($post->ID) . '">' . 'Read More' . '</a></span>';
    }
    add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link');

    here is what i use to add a thumbnail to every excerpt that has one everywhere my theme uses excerpts

    add_theme_support( 'post-thumbnails' );
    
    // add thumbnails, read more links and wrap excerpt in p tag
    function all_excerpts_get_more_link($post_excerpt) {
    	if ( has_post_thumbnail() ) {
    		$child_excerpt =  the_post_thumbnail( 'thumbnail' ) . '<p>' . $post_excerpt . '</p>' . '<p class="readmore"><a href="'. get_permalink($post->ID) . '">' . 'Continue Reading &raquo' . '</a></p>';
    	}
    	else {
    		$child_excerpt = '<p>' . $post_excerpt . '</p>' . '<p class="readmore"><a href="'. get_permalink($post->ID) . '">' . 'Continue Reading &raquo' . '</a></p>';
    	}
    	return $child_excerpt;
     }
    
    add_filter('wp_trim_excerpt', 'all_excerpts_get_more_link');
    Posted 3 years ago #
  9. brixon
    Member

    hi helga,

    this is fantastic. i also floated the img. left so that the text content sits right. looks great.

    however, it seems to be adding the thumb image to the very top left of the single post once you click inside it.

    is this just me?

    Posted 3 years ago #
  10. i'm sure you dont want to hear yes?. i just used this on a new site i was helping with and it worked as expected. are you for any reason using excerpts on the single post?

    Posted 3 years ago #
  11. brixon
    Member

    haha ok it must be something on my end. i'll look in to it. thanks for your help; you have been great!

    Posted 3 years ago #
  12. Helga, thank you very much!

    I just copied all the code from "//use excerpts on home page" to " 'new_excerpt_length'); " into the functions.php file in a child theme I'm doing, and it worked like a charm!

    Thematic is the way to go. I have a feeling I'll be developing all my sites with it!

    Mary Baum

    Posted 3 years ago #
  13. Mary- super glad you were able to find your answer on a 3 month old post. props to you for using the search! :) (even though i dont think the search is all that great)

    Posted 3 years ago #
  14. Hi, everyone. Helga, your code looked great. I wanted to try it, so I copied functions.php from the Thematic files into my child theme and added the code. My site wouldn't load, and when I tried to get into the admin panel, I then got a fatal error saying that I couldn't duplicate a part of the PHP (line 134 from functions.php).

    So rather than copying functions.php, I moved it to my child theme (read: copied it to my child theme's files and deleted it from the Thematic files, which I have a feeling isn't best practice). My site loaded again, but no excerpts.

    Is there a certain place I should put your code in my functions.php file? I just put it at the end before the closing PHP tag.

    I don't know if you need a reference, but my site is http://everydaytype.com.

    Thanks for any help you can provide!

    Posted 3 years ago #
  15. nickcox,

    i'm not really following you. no excerpts where? you should be doing all your work in your child theme's functions.php and NOT in thematic's functions.php you were correct in thinking that coding stuff into thematic files is not best practice

    the above code was working great for me 5 months ago and seems to still have been working a month ago. my guess is that you aren't properly closing something somewhere. empty out your functions.php and paste the bits back in one at a time to isolate which is causing the problem.

    since then i have developed a new way of handling excerpts that i use now

    http://forums.themeshaper.com/topic/how-to-make-excerpts-roll-over-and-say-uncle

    Posted 3 years ago #
  16. Hi Helga,

    Thanks for all the great advice and examples you have provided on this forum! I was wondering if you are familiar with a shortcode that will show only the excerpts you pass as an argument? I'd like to show child page excerpts in a 2-column TOC style page. An example can be seen here: http://sfrecpark.org/naProgramPage.aspx. I've run across a good plugin (sub page summary) which does this, however, I noticed that two thumbnails are showing, one from the subpage code, and one from thematic. If thematic can display excerpts out of the box, that would be great. The problem is I need to use this on many pages, not just the home page, and would hate to create a separate page template for each. Any advice you can offer would be much appreciated. Thanks,

    Sean

    Posted 3 years ago #
  17. if i am following your correctly (always debatable) then i think what you are attempting would require that you use get_pages() and then create a loop based off of the results. i'm not aware of a shortcode of plugin that does this (not to say there isn't one)

    you could then make the changes in 1 of a myriad of ways. you could:

    1. copy thematic's page.php into your child folder and edit that.
    2. create a template that just looks the same as page.php w/ the addition of the get_pages loop
    3. do this as a function and add it to the thematic_belowpost() hook on single pages

    Posted 3 years ago #
  18. Thanks for the quick reply. Rather than create many templates, I think I will try option three and look for a widget that can be contextually added.

    Sean

    Posted 3 years ago #
  19. you wouldn't need to create many templates- just one. then each time you create a page you add some metadata to that page (either as a custom field or preferably as a custom meta box) and use that data to generate the query arguments for get_pages().

    Posted 3 years ago #
  20. Hey, it's me again,

    I'm thinking of using the sub page summary plugin, which is doing a great job of displaying my excerpts...I might have to ditch the two column layout though.

    Sean

    Posted 3 years ago #
  21. i do love it when someone has already coded a solution

    Posted 3 years ago #
  22. yes, it saved me a lot of time and will be easy others to implement. Here is an example if you are interested:

    http://sstasio.org/sfrpd/?page_id=31

    Once again, thanks for your help

    One last thing, if I used the metadata, via a custom field or box, would I still have to pass the arguments in the page, or do I do it in the functions.php?

    Posted 3 years ago #
  23. neat work. to answer, i think you could do it either way - as a single template or as a function added to a hook. i think the the template might be easiest- b/c w/ the functions approach would be difficult to conditionally control. (unless you made a meta value that toggles it on or off)

    thematic has a blog template and i modified it and created metaboxes to let the user change the query arguments so that the blog template could show anything you like.

    this class has been super helpful to me:
    http://farinspace.com/wpalchemy-metabox/

    Posted 3 years ago #
  24. thanks for the link, I'll check that out tonight. One more question, can you recommend a html editor plugin? I've noticed that the TinyMCE adds <p> tags where I do not need them.
    Or, are you aware of a code editor plugin for editing the templates, css, or plugins? I know I can use dreamweaver, but it would be faster to use the wordpress stuff. Thanks, once again!

    Sean

    Posted 3 years ago #
  25. Helga,

    Thanks for the help.

    I'm kinda new to this, so I don't understand where that code goes. I tried to put it into functions.php, as the last function before the
    ?> at the end. Is that not right?

    I'm trying to make the landing page of my blog only excerpts. Right now, it only has full posts.

    For your reference again, it's
    http://everydaytype.com

    Posted 3 years ago #
  26. where what code goes? yes all php goes into your functions.php

    you want to switch your home (blog) page to use excerpts? already answered above... this is all you should need

    //use excerpts on home page
    function child_content($content) {
    	if ( is_home() ) {
    		$content = 'excerpt';
    	}
    return $content;
    }
    add_filter('thematic_content', 'child_content');
    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.