且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-11-30 14:47:46

假设您已为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.

希望这会有所帮助!