Solved

Wordpress Category display in Pages problem

Posted on 2009-07-10
6
522 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
  • 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 31

Accepted Solution

by:
gwkg earned 500 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now