?
Solved

Wordpress Category display in Pages problem

Posted on 2009-07-10
6
Medium Priority
?
530 Views
Last Modified: 2012-05-07
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.
<?php
/**
 * @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'));
?>
<?php 
 
if(is_page('Healthy Food')) {
query_posts('cat=you-and-your-baby&showposts=-1');
 
if(is_page('You and Your Baby')) {
query_posts('cat=you-and-your-baby&showposts=-1');
 
};
 
?>
 
			</div>
		</div>
 
		<?php endwhile; endif; ?>
 
</div>
 
<?php
 
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

0
Comment
Question by:jameshuckabonetech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 31

Expert Comment

by:gwkg
ID: 24825875
Have you looked over this page?

http://codex.wordpress.org/Template_Tags/query_posts

For one, you need to query the posts BEFORE you loop through them.
0
 
LVL 31

Expert Comment

by:gwkg
ID: 24825889
by "query the posts" I mean the function query_posts( )
0
 

Author Comment

by:jameshuckabonetech
ID: 24826673
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?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

Accepted Solution

by:
gwkg earned 1500 total points
ID: 24828793
I understand a little better now.  I think this page will help

http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates

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"

http://weblogtoolscollection.com/archives/2008/04/13/define-your-own-wordpress-loop-using-wp_query/
0
 
LVL 31

Expert Comment

by:gwkg
ID: 24828817
You also are missing a closing } on line 24 is that just a typo?
0
 

Author Closing Comment

by:jameshuckabonetech
ID: 31602169
Thanks for pointing me in the right direction!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why do you blog? It’s a question regular bloggers field from time to time, from folks with a preconceived notion that bloggers spend most of their days cranking away on a Comodore in their mother’s musty basement. (I’m an Altair guy myself.) The…
First things first, I say this in many of my articles, but in this one you can take it as fact. I am not in any way an expert when it comes to WordPress. I am strictly a user. I don't know the programming languages involved, and although I could pro…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question