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.
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
Thanks for the reply. Interesting bit of code. I see the
get_postcommand 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.
echo $address->post_contentexactly 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.
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().
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
I’ve used this myself, with perfect results. But if it doesn’t work for you, give the Improved Include Page plugin a try.
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).
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. 🙂
I do want to thank you for taking time to respond today.
I also tried the above code with
get_pageand 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. ?
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.
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.
- The topic ‘Want to put single custom posts in header and footer’ is closed to new replies.