I want to find a way for excerpt function to display exactly what i want inside a single post. the excerpt itself has starting and ending point as parameters to go and fetch the data. but what if i want to use words instead of them.
default:
$theExcerpt = get_the_content();
echo substr($theExcerpt,0,200);
I want this:
$theExcerpt = get_the_content();
echo substr($theExcerpt,'begining of paragraph', 'end of paragraph');
I want to find a way for excerpt function to display exactly what i want inside a single post. the excerpt itself has starting and ending point as parameters to go and fetch the data. but what if i want to use words instead of them.
default:
$theExcerpt = get_the_content();
echo substr($theExcerpt,0,200);
I want this:
$theExcerpt = get_the_content();
echo substr($theExcerpt,'begining of paragraph', 'end of paragraph');
1 Answer
Reset to default 1I think this is more a PHP than a WP question. Try using a regular expression with preg_match:
$theExcerpt = get_the_content();
$returnValue = preg_match('/(string01)(.*)(string02)/', $theExcerpt);
echo $returnValue[0];
You have to replace string01 and string02 with your 'begining of paragraph' and 'end of paragraph'. There might be a more elegant way of using preg_match, but I think this will do the trick.
Don't forget to escape the output
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744844770a4596765.html
评论列表(0条)