Last active
August 29, 2015 13:56
-
-
Save certainlyakey/9323610 to your computer and use it in GitHub Desktop.
Wordpress - custom content function with manual word limit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 .= '…'; | |
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(']]>', ']]>', $content); | |
} | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment