Wordpress' more tag not working for static pages
Yes, I know about the global $more variable trick but it didn't work out for me.
So here's a quick function to show a static page by ID until the WP more tag:
function get_post_content_and_title_until_more_tag($post_id){
// getting the post's content by id
$current_post = get_post($post_id);
$title = $current_post->post_title;
$link = get_permalink($post_id);
$raw_content = $current_post->post_content;
// look for the more tag
$splitted_content = split("<!--more-->", $raw_content);
// just in case there's no more tag
$before_more_tag_text = $raw_content;
if ( count($splitted_content) > 0 ) {
// it's there, take the first part only
$before_more_tag_text = $splitted_content[0];
}
// don't forget to apply the 'the_content' filter
$content = apply_filters(
'the_content', $before_more_tag_text
);
return sprintf(
'<h3 class="header">%s</h3>
<div class="wysiwyg">
%s
</div>
<a class="more" href="%s">more...</a>',
$title, $content, $link
);
}
Written by Bernard Chhun
Related protips
1 Response
nice function
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php more-tag
Authors
bchhun
1.193K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#