certainlyakey
3/3/2014 - 12:01 PM

Wordpress - custom content function with manual word limit

Wordpress - custom content function with manual word limit

//Custom content function with words manual limit
	function content($limit, $postid, $showmorelink = true) { //Normally, the second parameter provided is '$post->ID'
		$content = explode(' ', get_post_field('post_content', $postid), $limit);
		if (count($content)>=$limit) {
			array_pop($content);
			$content = implode(" ",$content);
			$content = preg_replace('/\[.+\]/','', $content);
			$content = apply_filters('the_content', $content);
			$content = str_replace(']]>', ']]>', $content);
			$content = strip_tags($content,'<br />');
			$content .= '&hellip;';
			if ($showmorelink) {$content .= ' <a class="more-link" href="'. get_permalink($postid) . '">Читать далее...</a>';}
		} else {
			$content = implode(" ",$content);
			$content = preg_replace('/\[.+\]/','', $content);
			$content = apply_filters('the_content', $content);
			$content = str_replace(']]>', ']]&gt;', $content);
		}
		return $content;
	}