Stripping images from post teasers/excerpts in Wordpress
In my theme I'm trying to display the excerpts or teasers of child pages, yet I do not want to display any imag开发者_StackOverflowes, I want image tags stripped out.
Once I've gotten the teaser in all its html glory in a php variable, how do I strip out the img tags prior to using echo?
And after you got the content in a html variable a small regular expression should do the rest
$content = preg_replace("/<img(.*?)>/si", "", $content);
Should do the trick
You probably want to use the semantics of in your pages, similar to how post excerpts work. You can get the list of subpages http://codex.wordpress.org/Template_Tags/wp_list_pages from here and then iterate over them (the above document has an example for styling the names of pages). you can then get the page contents with a custom function and do whatever you want with it.
http://www.mattvarone.com/wordpress/functionsphp-wordpress-themes/
That url explains how to add your own custom functions to a given theme.
You could use the the_excerpt()
which automatically grabs just the text or you can use a more sophisticated version of the same thing called The Excerpt Reloaded
精彩评论