Adding static content to Wordpress posts page? [closed]

半腔热情 提交于 2021-02-07 03:49:36

问题


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.

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.


回答1:


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.

Hope this helps!




回答2:


Assuming you want a hardcoded paragraph at the top of entries page before the list of all entries, Why not create a template page, assign it to your rate entries page and hardcode your paragraph in the code so it's always on the top.

Read about page templates here

Update

Have you tried doing a sticky post? that should solve your problem




回答3:


Here's what I've found that I had to insert into the index.php page in order to get what I need accomplished. Right before the loop that cycles through the posts as crowjonah had mentioned.

    <?php $page = get_page_by_title( 'Rate Entries' ); ?>
    <header class="entry-header">
        <h1 class="etnry-title"><?=$page->post_title;?></h1>
        <p><?=$page->post_content;?></p>
    </header>

What this does is take the page title and content for the page, and place it right above where the posts spill out. This way, she can edit that text, and it will update on the posts page.




回答4:


I solved this problem by using a text widget. By using a plugin called "Display widgets" I can make sure that this text only displays on the blog page.



来源:https://stackoverflow.com/questions/13589288/adding-static-content-to-wordpress-posts-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!