向Wordpress帖子页面添加静态内容? [英] Adding static content to Wordpress posts page?

查看:58
本文介绍了向Wordpress帖子页面添加静态内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我在Wordpress中的主页有一个静态页面.我还有一个名为费率条目"的页面作为我的博客页面.向我的客户展示此内容,然后向她展示Wordpress的admin部分后,她开始在 页面>>所有页面>>费率条目" >>编辑 .

I know I have a static page for my home page in Wordpress. I also have a page called "Rate Entries" as my blog page. After showing this to my client, and then showing her the admin section of Wordpress, she began typing a paragraph into Pages >> All Pages >> "Rate Entries" >> Edit.

众所周知,这里的最大问题是,如果"Rate Entries"是我的帖子页面,那么 page 内容就不会显示在那里,只有 posts .有什么方法可以将该页面内容添加到帖子页面的顶部?我曾希望找到一个插件来执行此操作,但无济于事.

The big problem here, as you all know, is that if "Rate Entries" is my posts page, that page content does not show there, only the posts. Is there any way to add that page content to the top of the posts page? I had hoped to find a plugin to do this, but to no avail.

推荐答案

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

Assuming you've set a custom page for the posts in the Wordpress backend (Settings > Reading), you just need to add a few lines of code to your index.php file in your theme. Like so:

//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
}

根据您的情况,您可以添加代码以在该代码下方显示循环.

In your case, you can add the code to display the loop below this code.

希望这会有所帮助!

这篇关于向Wordpress帖子页面添加静态内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆