dougu4704 2014-07-03 18:27
浏览 56
已采纳

Wordpress - 在不使用循环的情况下显示页面内容

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!

  • 写回答

1条回答 默认 最新

  • dswm97353 2014-07-03 18:57
    关注

    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']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?