• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 539
  • Last Modified:

Wordpress Category display in Pages problem

I'm having two problems related to the same ambition.

Using the default Wordpress theme, I created a page for each section of my website. Then I created a category to match each of those pages. I want to be able to create a post, assign that post a category, and then have it appear in it's corresponding page with the ability to comment on that post. I figured out that I needed to add query_posts(); to the page template. This sort of works but here's the problems I'm having with it:

1) I can't figure out the proper if statements to organize it all properly, it is showing all posts on all pages I do it for.

2) The posts it displays has no comment or rss fields. So they are just static. I want people to be able to comment on my posts.

P.S. If I don't use the query_posts(); function then comments will work!

This is what I have for my page.php template.
 * @package WordPress
 * @subpackage Default_Theme
get_header(); ?>
	<div id="content" class="narrowcolumn">
		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
		<div class="post" id="post-<?php the_ID(); ?>">
		<h1><?php the_title(); ?></h1>
			<div class="entry">
				<?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
				<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number'));
if(is_page('Healthy Food')) {
if(is_page('You and Your Baby')) {
		<?php endwhile; endif; ?>
if(is_page('1')) {
     echo 'Hi There!';
} elseif (is_page('Healthy Food')) {
     echo '<div id=sidebar>
<h1>Featured Product</h1><p class="centered">DERMAdoctor<br /><a href=http://click.linksynergy.com/fs-bin/click?id=mir9zur4eS8&offerid=30329.10000043&type=4&subid=0><img width=120 height=60 alt=Banner 10000043 border=0 src=http://www.dermadoctoraffiliates.com/graphics/images/alwaysin120x60.gif></a><img border=0 width=1 height=1 src=http://ad.linksynergy.com/fs-bin/show?id=offJEA3lmBg&bids=mir9zur4eS8&type=4&subid=0></p>
<p>For sheer information, it\'s tough to beat DERMAdoctor\'s feature articles and newsletters where Dr. Kunin shares the most current developments in skin care technology and research. This is what separates DERMAdoctor.com from other retailers on the web.</p>
<p>Accurate information gives you the power to make the right skin care choices from our wide array of products. And for the shopper in a hurry, some guests prefer to browse the extensive listings of products and descriptions.</a></p></div>';
} elseif (is_page('How You Clean')) {
     echo '<div id="sidebar">
<h1>Featured Product</h1><p class="centered">Aquasana.com<br /><a href=http://www.aquasanaaffiliates.com/b.asp?id=4270>
<img src=http://www.aquasanaaffiliates.com/showban.asp?id=4270&img=banner7.jpg border=0></a></p><p>This water filter is perfect for your home. We have done our research and have found this to be the most economical solution available. We give it our full endorsement and know youll just love the system.</p></div>';
} elseif (is_page('Around the House')) {
     echo '<div id=sidebar><p><a href="http://www.greensuperfood.com/?Click=4578">Click here to visit greensuperfood.com</a></p></div>';
} elseif (is_page('Out and About')) {
     echo '<div id=sidebar>Out and Aboot</div>';
} elseif (is_page('You and Your Baby')) {
     echo '<div id=sidebar>You & Bebeh</div>';
} elseif (is_page('Healthy Pets')) {
     echo '<div id=sidebar>Smetz</div>';
else {
     echo '<div id="sidebar"><h1>Featured Product</h1><p class="centered">Bulk Herbs - Great Value!<br /><br />
If you&#39;re looking to buy in quantity and want a great low price, then check out these guys:<br /><br /> 
<a href="http://www.morethanalive.com/?a_aid=e970b042&amp;a_bid=75abec25"><img src="http://join.morethanalive.com/scripts/sb.php?a_aid=e970b042&amp;a_bid=75abec25" alt="www.morethanalive.com" border="0" title="www.morethanalive.com"></a></p></div>';
<?php get_footer(); ?>

Open in new window

  • 4
  • 2
1 Solution
Have you looked over this page?


For one, you need to query the posts BEFORE you loop through them.
by "query the posts" I mean the function query_posts( )
jameshuckabonetechAuthor Commented:
Well, the thing is, I want the specific page's text to come up first, and then the post that are marked with that page's category to appear under that. For Instance, if the page is called "You and your baby". I want to have an introductory paragraph for that section. And then underneath that introductory paragraph I would like all of the posts that I categorized as "you-and-your-baby" (created a category similar to the page name) to appear underneath the introductory paragraph. It seems thats if I put the query_posts function before the loop, then it overrides the display of the page text I created. Am I making any sense?
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

I understand a little better now.  I think this page will help


Especially look at  'A Page of Posts' and how they use WP_Query($args); to display the posts from a specific category on a page.

This explains WP_Query to start a new "loop"

You also are missing a closing } on line 24 is that just a typo?
jameshuckabonetechAuthor Commented:
Thanks for pointing me in the right direction!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now