• Resolved David Borrink

    (@davidborrink)


    I’d like to put a single post in a header for address/phone number, and also a single post in a footer for the copyright/disclaimer. I’d like to use posts so that these can be edited as posts, not as php files which have to be ftp’d. This allows ALL content to be available as posts.

    This would require three loops, obviously. I’ve read about using multiple loops at http://codex.wordpress.org/The_Loop#Multiple_Loops and while I think I understand what’s being presented, the example shown at “Multiple Loops in Action” (down the page a little bit), seems to be set up for doing two loops within the main content divs if I read it right.

    I tried the examples of a single specific category loop in the header and the header post wouldn’t show, but the page text did show. I didn’t try a loop for the footer, yet.

    I’d like some advice about being able to put a single post in the header (with a unique category called “address”) and in the footer (with it’s own unique category) while still having regular content on the page. I plan on using pages for the content, so no blog page using index.php is being planned at the moment. But if a blog page was to be added later, I’d need these items to work.

Viewing 11 replies - 1 through 11 (of 11 total)
  • I would use Pages for this, rahter than Posts. But you want to use get_post() for this.

    <?php
    $address = get_post(X) // X is the ID of the Post/Page
    setup_postdata($address);
    the_content();
    ?>

    This should work. If the_content() doesn’t work, try echo $address->post_content

    Thread Starter David Borrink

    (@davidborrink)

    Hi stiand,

    Thanks for the reply. Interesting bit of code. I see the get_post command would replace a loop inquiry.

    I put your code in the header within the appropriate div, and placed the correct post ID number in X, … and I got a blank page as a result.

    I replaced the_content() with echo $address->post_content exactly as you mentioned and that also produced a blank page.

    I note the get_post() reference you linked to has some different syntax with the id number.

    I’m currently using content typed into the header.php file within a div and it’s styled properly on style.css so I know the text will work there.

    Thread Starter David Borrink

    (@davidborrink)

    Remember, this is to call up one post in a div in the header, then the regular page (not index.php, but page.php) content, then I’d call up one post in a div in the footer.

    Is it a Post or a Page? If you’re using a Page you might wanna try get_page().

    Both get_post() and get_page() take an integer, the ID for the Post/Page. Everything else is optional. You can choose to get an array returned, instead of an object, but as we’re takling a single Page here, an object (default) is a-okay. Try using the code above, and exchange get_post() with get_page().

    I’ve used this myself, with perfect results. But if it doesn’t work for you, give the Improved Include Page plugin a try.

    Thread Starter David Borrink

    (@davidborrink)

    I’m using Pages for the site, with no blog page, so index.php is not being used (but could be used in the future). So I want a post to appear in the header on a Page, actually all pages for that matter. And a post in the footer.

    I guess I could use pages for the content, at the moment I have a navigation menu which lists all the pages, so I’d have to “hide” those two custom pages from the navigation (the one for the addresses and the one for the disclaimer).

    Thread Starter David Borrink

    (@davidborrink)

    I tried your get_page() idea after creating a page with content and making it a second level page by putting it under a parent page (keeping it out of the navigation menu which is set at a depth of 1), and this didn’t work either. Still a blank page.

    I found another code idea from another forum and adapted it as follows

    <?php //Test single post
    global $post;
    $myposts = get_posts('p=219');
    foreach($myposts as $post) :
    ?>
    <?php the_content();?>
    <?php endforeach; ?>

    Note: 219 is the id number for my post that would be called up in the header.

    What happened this time is: I got a page up, but the div which was to hold my addresses post contained the content of the Page below, styled in the correct style for this div. And the content was duplicated below in the page, and correctly styled for a page.

    I clicked on other Pages and the same thing happened: regardless of the post id number in the code, the Page’s content appeared in that header div.

    Any ideas? I’m getting content in the div now, but it’s not the right stuff. 🙂

    Thread Starter David Borrink

    (@davidborrink)

    I do want to thank you for taking time to respond today.

    I also tried the above code with get_page and the new page’s id number, and it’s goes blank. If I tried get_pages (plural), I get a page, but the Page’s content is repeated 7 times. ?

    Thread Starter David Borrink

    (@davidborrink)

    I went with the Improved Include Page plugin and it’s working fine. That will do it for me.

    My guess is that the PHP in the surrounding codes are interfering somehow with your code suggestion. I’m glad it works for you. You probably don’t start with the Default theme all the time for the basis of your sites, like I do. It might be a conflicting command in the Default theme.

    Improved Page plugin is nice and simple. Thanks for the tip! And your time.

    On a related note:

    I’d like to use posts so that these can be edited as posts, not as php files which have to be ftp’d

    For future reference, you can just edit the files from Appearance|Editor from the WP dashboard.

    Thread Starter David Borrink

    (@davidborrink)

    True. I realize that. But I’m trying to keep it simple for my client so that they only have to edit via the post/page editing windows. I’d like to keep them away from the PHP. Too many risks for those out-of-the-know.

    I see now that setup_postdata($address); might mess up the Loop, so you should probably drop it entirely, and use echo $address->post_content instead of the_content().

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Want to put single custom posts in header and footer’ is closed to new replies.