static page that also shows posts
-
Hi there, I’m new to WordPress so forgive me if this question is obvious.
I am currently working on a 6 page site using WordPress as the CMS. All 6 pages of the site (this does not include the home page) will include static information that I would like to keep updated once and a while. However, on three of the pages I would like to show posts from one specific category (for example on page 2 I would like to show static content as well as posts from category 5, page 3 — category 3, etc).
So far in my page.php template I have set up the loop twice. Once to show the page content, and the second time I use an if statement and query post, then run the loop again – it looks like this:
`<?php
if (is_page(‘2’) ){
query_posts(“category_name=test-category-one”);
}
?><?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<h4><?php the_time(‘F jS, Y’) ?>
<?php /*?><!– by <?php the_author() ?> –> · <?php comments_popup_link(‘No Comments’, ‘1 Comment’, ‘% Comments’); ?><?php */?>
</h4>
<div class=”entry”>
<?php the_content(‘<p>Read the rest of this page →</p>’); ?>
<?php link_pages(‘<p>Pages: ‘, ‘</p>’, ‘number’); ?>
</div>
<?php if (‘open’ == $post-> comment_status) { ?>
<p class=”tagged”>#comments”><?php comments_number(‘No Comments’, ‘1 Comment’, ‘% Comments’); ?></p>
<div class=”clear”></div>
<?php } else { ?>
<div class=”clear rule”></div>
<?php } ?><?php endwhile; endif; ?>`
The problem is this:
1. I could use a few if statements to go through the pages / categories – but I was hoping there was a cleaner or more efficent way of doing this.2. For the pages that I don’t want posts to appear on, the loop just repeats and the page content appears twice.
Does anyone have any suggestions – Just a reminder I’m new to WordPress and still a bit green with PHP.
- The topic ‘static page that also shows posts’ is closed to new replies.