Return to Snippet

Revision: 48344
at June 29, 2011 07:27 by wahnbriefe


Initial Code
<?php
	$my_id = 22; // change to relevant page ID
	$post_id_5369 = get_post($my_id);
	$content = $post_id_5369->post_content;
	$content = apply_filters('the_content', $content);
	$content = str_replace(']]>', ']]>', $content);
	$words = explode(' ', $content);
	$i = 0;
	while ($i <= 20) { 
		$short .= $words[$i] . ' ';
		$i++;
	}
		echo $short;
?>

Initial URL


Initial Description
This gets the content from the page with the ID 22 (change as appropriate on line 1) and echos the first 20 words (change word count on line 8) - can be used on any page inside your Wordpress theme.

Initial Title
echo first 20 words of any page

Initial Tags
wordpress

Initial Language
PHP