WordPress.org

Ready to get started?Download WordPress

Forums

List category posts
Excerpt - keep formatting by editing catlist.php (13 posts)

  1. jamesthecat7
    Member
    Posted 2 years ago #

    Hi everyone,

    I would like to keep HTML markup in Excerpts. I've found the code catlists.php which strips any markup but my php isn't too good and would like to allow <span> and <p> in excerpts. Please advise, code is below from line 228:

    public function get_excerpt($single){
    		if (
    				$this->params['excerpt']=='yes' &&
    				!($this->params['content']=='yes' &&
    				$single->post_content) ){
    			/*
    			 * Strip shortcodes - #5
    			 * http://codex.wordpress.org/Function_Reference/strip_shortcodes
    			*/
    			if($single->post_excerpt){
    				return $single->post_excerpt;
    			}
    
    			$lcp_excerpt = strip_shortcodes(strip_tags($single->post_content));
    			$exc_lim = intval($this->params['excerpt_size']);
    			$lcp_excerpt = mb_substr($lcp_excerpt, 0, $exc_lim) . '...';
    			return $lcp_excerpt;
    		} else {
    			return null;
    		}
    	}

    http://wordpress.org/extend/plugins/list-category-posts/

  2. jamesthecat7
    Member
    Posted 1 year ago #

  3. Mpalmer22
    Member
    Posted 1 year ago #

    Don't use the code you posted. That's more than you need to do. Use the link you posted. Paste the code into your functions.php file (the big chunk) and then edit the line 22 that says allowed tags. You have to allow certain tags to show up. This will edit excerpts across the site.

  4. jamesthecat7
    Member
    Posted 1 year ago #

    Hiya, thanks for the response.
    I'm using the mystique theme however functions.php appears to have <p> as an allowed tag already.

    I assumed the plug-in did not share the rules in function.php and used its own rules?

  5. Mpalmer22
    Member
    Posted 1 year ago #

    I'm still not entirely sure what you are trying to accomplish with the site. If you paste the code from your link into the bottom of you functions.php file and edit the lines as per the tutorial, then anywhere (in the theme) that calls for your excerpt will allow the html tags you specified from the original post.
    I don't think it will work if you use the plugin though, since it appears the plugin is making it's own excerpt and not using wordpress features to make the excerpt. Where are you trying to get the excerpt to show up?

  6. geologist
    Member
    Posted 1 year ago #

    Could someone please answer the first question Jamethecat7 asked? The bottom line is MANY of us are using this extremely effective plugin and we need to modify the PLUGIN code, not core WordPress code.

    We need to be able to allow HTML tags so that we can format the inside of the excerpt. For instance, I need the excerpt to style both <p> and <h3>.

    My page of excerpts: http://www.palmyracob.org/honest/about-us/meet-our-staff/.

    If you look at the very bottom excerpt for Missy Thompson, in the first line of the excerpt "Children’s Ministry Mobilize" is styled with an <h3> tag in the original post. But the Plugin strips out the html tags inside the excerpt. There must be a way to get the Plugin to recognize html tags in the excerpt.

    Can someone please answer the original question in this thread - how to modify the Plugin code?

  7. Mpalmer22
    Member
    Posted 1 year ago #

    Untested, but try this.
    Change this line:
    $lcp_excerpt = strip_shortcodes(strip_tags($single->post_content));

    to

    $lcp_excerpt = strip_shortcodes(strip_tags($single->post_content, '<h3><any other tags you want>'));'

    Should work, if not you may need to allow tags in your excerpts too. There's a bunch of tutorials on that though.

  8. geologist
    Member
    Posted 1 year ago #

    Mpalmer22,

    Thanks for your suggestion. I haven't tried it yet. I received another suggestion and have been trying to get it to work.

    Believe me, if I find anything that works, I will make sure to post it on this forum.

  9. geologist
    Member
    Posted 1 year ago #

    Unfortunately, I couldn't get Mpalmer22's suggestion to work. Maybe it's just the theme I'm using which is "Swift".

    Sure would be helpful if the Plugin developer would address the problem of having html tags stripped from the Plugin excerpt.

  10. oliveiravinicius
    Member
    Posted 1 year ago #

    I am also having the same difficulty. I've tried everything and could not resolve this issue. If the developer can help would be great. Thank you in advance and excuse my english.

  11. oliveiravinicius
    Member
    Posted 1 year ago #

    I managed to make the HTML tags appear. Just change the following line to this:

    //$lcp_excerpt = strip_shortcodes(strip_tags($single->post_content));
    $lcp_excerpt = $single->post_content;

    public function get_excerpt($single){
    		if (
    				$this->params['excerpt']=='yes' &&
    				!($this->params['content']=='yes' &&
    				$single->post_content) ){
    			/*
    			 * Strip shortcodes - #5
    			 * http://codex.wordpress.org/Function_Reference/strip_shortcodes
    			*/
    			if($single->post_excerpt){
    				return $single->post_excerpt;
    			}
    			$lcp_excerpt = $single->post_content;
    			$exc_lim = intval($this->params['excerpt_size']);
    			$lcp_excerpt = mb_substr($lcp_excerpt, 0, $exc_lim) . '...';
    			return $lcp_excerpt;
    		} else {
    			return null;
    		}
    	}
  12. oliveiravinicius
    Member
    Posted 1 year ago #

    However now my question is this, would like the excerpt was the entire content that is above the tag <!- more ->, one would have any idea how to do this?

  13. geologist
    Member
    Posted 1 year ago #

    Thanks for the suggested code. I'll give it a try.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic