将静态内容添加到 Wordpress 帖子页面?

Vin*_*tto 4 wordpress blogs

我知道我的 Wordpress 主页有一个静态页面。我还有一个名为“Rate Entries”的页面作为我的博客页面。在向我的客户展示这个,然后向她展示 Wordpress 的管理部分后,她开始在Pages >> All Pages >> "Rate Entries" >> Edit 中输入一个段落。

众所周知,这里的大问题是,如果“评分条目”是我的帖子页面,则该页面内容不会显示在那里,只显示帖子。有没有办法将该页面内容添加到帖子页面的顶部?我曾希望找到一个插件来做到这一点,但无济于事。

Ste*_*ven 5

假设您已经为 Wordpress 后端(设置 > 阅读)中的帖子设置了自定义页面,您只需将几行代码添加到主题中的index.php文件中。像这样:

//grab the id of the page set in the backend 
$posts_page_id = get_option('page_for_posts');

//grab the post object related to that id
$posts_page = get_post($posts_page_id);

//display the content if any
if( $posts_page->post_content ){
    echo wpautop( $posts_page->post_content ); //uses wpautop to automatically add paragraphs
}
Run Code Online (Sandbox Code Playgroud)

在您的情况下,您可以添加代码以显示此代码下方的循环。

希望这可以帮助!