2

Confusing title, I know. Let me explain.

Currently, I have this little guy set up in my Wordpress theme:

<?php 
    $id=7; 
    $post = get_post($id); 
    $content = apply_filters('the_content', $post->post_content);
    echo $content;  
?>

What this does is it displays the content from a certain page of my choice.

Works great! Bravo! Fantastic! The only problem is that I'd like to only show the content before the read more-tag, not ALL of it. And that is where I'm at a loss.

My research (incessant googling, cursing and hammering om my keyboard) has lead me to understand that I could achieve this within a loop. But as I am only going to display the one page that seems a bit redundant.

Also, I'd rather not use the_excerpt as that means the end user won't be able to change the content later on.

Thanks for reading and I hope you can help! Cheerio!

gburning
  • 486
  • 6
  • 19
  • I'm not sure what you mean by the excerpt not being changable, but if you're looking for a basic WP truncation method see my answer on this question: http://stackoverflow.com/questions/9219795/truncating-text-in-php – Kai Qing Jul 03 '14 at 18:31
  • Thanks for the answer! But the way I need this to be changeable is from within the Admin-section. My client isn't exactly that tech-savvy and won't be able to go into the theme files to change things like this. – gburning Jul 03 '14 at 18:48

1 Answers1

4

Use the WordPress function get_extended($post_content) to retreive text in content before the <!--more--> tag.

For example:

$id=7; 
$post = get_post($id); 
$content_arr = get_extended($post->post_content);
echo apply_filters('the_content', $content_arr['main']);