Hi!
Just started using WP this week and trying to modify a theme.
I'd like to add an "about" snippet to the header area and would like to know what is the better way to do so.
Create a page and use queryposts to load the contents.
Or
Create a new widget area and use a text widget.
Thanks!
If you don't need WYSIWYG and/or are happy using raw markup, I'd go with the widget route myself. Otherwise you will need a page plus get_posts or query_posts. If you use the latter, just remember to reset the query before the main Loop.
Thanks, for the reply.
I'd like to try both, in the meantime I tried the page approach.
using the following code I keep getting the first post.
<?php
// retrieve one post with an ID of 5
query_posts('page_name=about');
global $more;
// set $more to 0 in order to only get the first part of the post
$more = 0;
// the Loop
while (have_posts()) : the_post();
// the content of the post
the_content('Read the full post ยป');
endwhile;
wp_reset_query();
?>
got this code from
http://codex.wordpress.org/Template_Tags/query_posts
Any suggestions?
Assuming your About page has a page id of 23, try using:
<?php
$about_page = get_posts('page_id=23');
foreach($about_page as $about) :
setup_postdata($post);
?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_content(); ?>
<?php endforeach; ?>
This seems to get the current pages content, not the about page. Am I doing something wrong? Is there a particular area I should be putting the code?
You need to place the code in header.php after the opening <body> tag but well before any other Loop. Make sure that you are using the correct id for the About page.
esmi, That's exactly where I placed it.
I've given up on this route for now - it ignores the page id and loads the current page still. I following your suggestion on another post and used a sidebar widget. Thanks!