Solved

Wordpress Page of Posts Problem

Posted on 2009-07-15
3
821 Views
Last Modified: 2013-12-13
I have been having some trouble (i don't know any PHP) setting up wordpress to display posts from a specific category, based on what page is currently displayed (page.php below). I was pointed to this page (look at page of posts) for help but now I'm stuck. Can someone help me figure out the last details of this? Thanks a lot!

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


<?php
/**
 * @package WordPress
 * @subpackage Default_Theme
 */
 
get_header(); ?>
 
 
	<div id="content" class="narrowcolumn">
<?php
// page id 21 will get category ID 12 posts, page 16 will get category 32 posts, page 28 will get category 17 posts
if (is_page('Healthy Food') ) {
$cat = array('healthy-food');
} elseif ( is_page('How You Clean') ) {
$cat = array('how-you-clean');
} elseif ( is_page('You and Your Baby') ) {
$cat = array('you-and-your-baby');
} else {
$cat = '';
}
 
$showposts = -1; // -1 shows all posts
$do_not_show_stickies = 1; // 0 to show stickies
$args=array(
   'category__in' => $cat,
   'showposts' => $showposts,
   'caller_get_posts' => $do_not_show_stickies
   );
$my_query = new WP_Query($args); 
 
?>
 
 
<?php if( $my_query->have_posts() ) : ?>
 
		<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
			<?php
			//necessary to show the tags 
			global $wp_query;
			$wp_query->in_the_loop = true;
			?>
			<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
				<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
				<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
 
				<div class="entry">
					<?php the_content('Read the rest of this entry »'); ?>
				</div>
 
				<p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
			</div>
 
		<?php endwhile; ?>
 
	<?php else : ?>
 
		<h2 class="center">Not Found</h2>
		<p class="center">Sorry, but you are looking for something that isn't here.</p>
		<?php get_search_form(); ?>
 
	<?php 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
  • 2
3 Comments
 
LVL 4

Expert Comment

by:rondelrosario
ID: 24911306
What exactly do you want to achieve?
0
 

Author Comment

by:jameshuckabonetech
ID: 24919039
"setting up wordpress to display posts from a specific category, based on what page is currently displayed (page.php below)"
0
 

Accepted Solution

by:
jameshuckabonetech earned 0 total points
ID: 24947940
I'm sorry, I thought I was clear but I guess not. My site is at http://www.purelifenaturals.com. I've created pages in wordpress that the navigation bar items are linked to. I've also created corresponding categories in Wordpress. I would like to be able to write a post and assign it to the category/page that it should belong to. Then, when someone clicks on an item in the navigation bar for instance, I would like the page to appear with all of the posts that have been put into that category to appear. This seems like it should be a built in feature since it is a simple way to automatically organize things. I always hated how blogs would by default have the newest articles appear on the home page and then have the old posts go into an archive that is cumbersome to click through. So yah, can anyone help out?
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
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…

740 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