wp query - How to create page with post content in it?

I have a page that I would like users to remain on. It is like a reference guide.Hence I would like to load post content

I have a page that I would like users to remain on. It is like a reference guide.

Hence I would like to load post content into the page without the header / sidebar etc. Just the post content.

Example:

A dog is man's best friend. You can read more about it below.
<Post Title>
<Post Content>
You can also search for more animals here.

Do kindly assist.

I have a page that I would like users to remain on. It is like a reference guide.

Hence I would like to load post content into the page without the header / sidebar etc. Just the post content.

Example:

A dog is man's best friend. You can read more about it below.
<Post Title>
<Post Content>
You can also search for more animals here.

Do kindly assist.

Share Improve this question edited Jun 4, 2019 at 6:00 nmr 4,5672 gold badges17 silver badges25 bronze badges asked Jun 4, 2019 at 5:51 MorMor 1 4
  • You can do it with including wp-config.php and also include the global $wpdb; in your file. – Tejas Gajjar Commented Jun 4, 2019 at 6:06
  • could you be kind enough to go into details.. i am clueless.. ( not a dev ) – Mor Commented Jun 4, 2019 at 6:30
  • Is that reference guide also a wordpress page? Or external stuff? – maryisdead Commented Jun 4, 2019 at 8:49
  • hi . . the reference guide is a wordpress page.. so basically i am trying to show contents of posts in a page ( without showing the header / side bar / footers that usually comes with the post ) – Mor Commented Jun 4, 2019 at 9:16
Add a comment  | 

1 Answer 1

Reset to default 0

You might get away with shortcodes:

add_shortcode('title', function ($atts, $content = null) {
    $atts = shortcode_atts([
        'id' => null,
    ], $atts);

    $title = '';

    if (!empty($atts['id'])) {
        $title = get_the_title($atts['id']);
    }

    return $title;
});

add_shortcode('content', function ($atts, $content = null) {
    $atts = shortcode_atts([
        'id' => null,
    ], $atts);

    $content = '';

    if (!empty($atts['id'])) {
        $post = get_post($atts['id']);

        // Full content, disregarding "read more" tags:
        $content = str_replace('<!--more-->', '', $post->post_content);
        $content = apply_filters('the_content', $content);

        // Alternatively, simply use this which respects "read more" tags.
        #$content = apply_filters('the_content', $content);
    }

    return $content;
});

Drop this into functions.php of the theme you are using.

In your page you can then use [title id="42"] and [content id="42"], where 42 is the ID of the post you want to display.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745439671a4627772.html

相关推荐

  • wp query - How to create page with post content in it?

    I have a page that I would like users to remain on. It is like a reference guide.Hence I would like to load post content

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信