WordPress.org

Ready to get started?Download WordPress

Forums

Post by ID in separate divs (5 posts)

  1. hrrubin
    Member
    Posted 9 months ago #

    I'm going to have a single page with some divs, each of which are getting a post made specific for that div.

    So far I got:

    <div id="wc-1">
    	<div class="content">
            <?php
    		$my_id = 1;
    		$post_id_1 = get_post($my_id);
    		$title = $post_id_1->post_title;
    		echo '<h1>' . $title . '</h1>';
    		?>
    	</div>
    </div>
    <div id="wc-2">
    	<div class="content">
            <?php
    		$my_id = 80;
    		$post_id_1 = get_post($my_id);
    		$title = $post_id_1->post_title;
    		echo '<h1>' . $title . '</h1>';
    		?>
    	</div>

    It does get the h1 title of course, but what I can't figure out is how to retrieve the rest.

  2. alchymyth
    The Sweeper & Moderator
    Posted 9 months ago #

    please specify what you mean with 'retrieve the rest'.

    have you reviewed http://codex.wordpress.org/Function_Reference/get_post

  3. hrrubin
    Member
    Posted 9 months ago #

    I want h1 and paragraphs and images. Basically what is in a post.

    I have viewed the link, but couldn't find help for me.

  4. alchymyth
    The Sweeper & Moderator
    Posted 9 months ago #

    'paragraphs and images' aka post content;

    try for example:

    $content = $post_id_1->post_content;
    		echo '<div>' . apply_filters( 'the_content', $content ) . '</div>';
  5. hrrubin
    Member
    Posted 9 months ago #

    Thank you, it's working.

    If I was to style that content, how would I go about it? Would it be good enough to for example:

    #wc-1 h1{} or #wc-1 p{} ?

    Update: Yes, that should do it. Thanks for your time.

Reply

You must log in to post.

About this Topic