簡體   English   中英

如何添加 WORDPRESS 在帖子列表上方顯示 STATIC 帖子頁面的內容

[英]How To Add WORDPRESS SHOW CONTENT OF STATIC POSTS PAGE ABOVE POSTS LIST

有什么方法可以將內容添加到我的 WordPress static 博客頁面。

我試圖安裝插件它不工作。

其他一些來源

方法一:將以下代碼粘貼到function.php

// Add content of page called “blog” to the page that contains the list of blog posts
add_action ( ‘__before_loop’, ‘add_blog_page_content_before_post_list’);
function add_blog_page_content_before_post_list() {
if ( is_home() ) {
$post = get_page_by_path( ‘/blog’ );
echo wpautop($post->post_content);
}
}

源鏈接 – https://presscustomizr.com/snippet/enter-text-posts-static-blog-page/

方法二:

假設您已經為 WordPress 后端(設置 > 閱讀)中的帖子設置了自定義頁面,您只需在主題中的 index.php 文件中添加幾行代碼。 像這樣:

//獲取后端設置的頁面id $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
}

源鏈接—— 將 static 內容添加到 Wordpress 帖子頁面?

方法三:

global $post;
$page_for_posts_id = get_option('page_for_posts');
if ( $page_for_posts_id ) : 
    $post = get_page($page_for_posts_id);
    setup_postdata($post);
    ?>
    <div id="post-<?php the_ID(); ?>">
        <header>
        <h1><?php the_title(); ?></h1>
        </header><!-- .entry-header -->
        <div>
            <?php the_content(); ?>
            <?php edit_post_link('Edit', '', '', $page_for_posts_id); ?>
        </div>
    </div>
    <?php
    rewind_posts();
endif;

來源鏈接: https://www.thatweblook.co.uk/tutorial-wordpress-show-content-of-static-posts-page-above-posts-list/?unapproved=11768&moderation-hash=f5c2e41fcea7e044a9e46798f94703dd#comment-11768

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM