How to load a post into an empty div tag anywhere across the pages?

Absolute beginner question:
I need to load text into specific div tags across the page.
On my html mockup its a lorem ispum text box waiting for wordpress to load the real content.
So, how do i control the real content and its relation with the div box text on the page?
Can it be a post, so i can manage it from the dashboard?
Thanks in advance.

Related posts

Leave a Reply

1 comment

  1. You can solve this in different ways.

    One it’s to use simple querys with WP_Query and using the p parameter to retrive a particular post like it’s explained here.
    Something like this:

    $the_query = new WP_Query( 'p=123' );
    while ( $the_query->have_posts() ) : $the_query->the_post();
        the_content();
    endwhile;
    

    Where 123 it’s the post id from where you need the data (the_content).

    Or you can query the content from a single post using get_post function.
    Like this:

    $postid = 123;
    $queryp = get_post($postid);
    $content = $queryp->post_content;
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]>', $content);
    echo $content;
    

    Where 123, again, it’s the postid from where you need to extract the content.

    And i think wp_get_single_post function should work too.

    Then you can control your content everywhere just extracting the desired data from certains posts by postid