Sign up to create your own snipts, or login.

Public snipts » depi's snipts » Get the nth sentence from the post (beta)

posted on Feb 03, 2010 at 1:55 p.m. EST in 
  • <?php
    function the_nth_sentence($sentence_num = 1) {
    	if ($sentence_num == 0) {
    		return false;
    	}
    	if ($sentence_num >= 1) {
    		$sentence_num = $sentence_num-1;
    	}
    	$content = get_the_content('',FALSE,'');
    	$content = apply_filters('the_content', $content);
    	$content = strip_tags($content);
    	$pos = strpos($content, '.');
    	for($i=1; $i<=$sentence_num; $i++) {
    		$pos = strpos($content, '.', $pos+1);
    	}
    	echo '<p>' . substr($content,0,$pos+1) . '</p>';
    }
    ?>
    

    copy | embed

0 Comments

Sign up, or login to leave a comment.