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

时间:2014-07-03 18:27:17

标签: php wordpress

令人困惑的头衔,我知道。让我解释一下。

目前,我在Wordpress主题中设置了这个小家伙:

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

这样做是显示我选择的某个页面的内容。

效果很好!好样的!太棒了!唯一的问题是我只想在读取更多标签之前显示内容,而不是全部。这就是我不知所措的地方。

我的研究(不断的谷歌搜索,诅咒和锤击我的键盘)让我明白我可以在一个循环中实现这一点。但是因为我只会显示一个看起来有点多余的页面。

此外,我宁愿不使用the_excerpt,因为这意味着最终用户以后将无法更改内容。

感谢您的阅读,希望您能提供帮助! Cheerio!

1 个答案:

答案 0 :(得分:3)

使用WordPress功能get_extended($post_content)检索<!--more-->标记之前的内容中的文字。

例如:

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