PS. I’m aware I’ll probably be looking at query_posts here?
Hi
This code goes before the wordpress loop in your page.php template. I think you are saying you want two categories displaying on one page. I am as an example assuming that the page slug for the page you want these displayed on is faq
This code only affects that one page – all other pages will display normally.
<?php
$cats = '';
if (is_page('faq')) {
$cats='cat=5,6'
}
if ($cats) {
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("$cats&paged=$paged");
} ?>
Now the WP loop starts
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
I set this up to make it easy to add additional pages / categories
See http://codex.wordpress.org/Template_Tags/query_posts for more details
@stvwlf – You’re the man dude. That works a treat.
I’m off to educate myself about query_posts() now then :]
Thanks a lot,
L
Is there a reason you’ve included paged in this? The following seems to work fine, I’m just curious:
<?php
$cats = '';
// if page is faq/blog page
if (is_page('6')) {
$cats = 'cat=5,6';
} // if page is case studies page
elseif (is_page('7')) {
$cats = 'cat=7';
}
// query appropriate category content
query_posts($cat);
?>
I’ve read this (http://codex.wordpress.org/Category_Templates#Text_Displaying_Only_on_First_Page_of_Archive); but my (old) problem didn’t include an archive page. I interpret the benefit of what’s being said behind the previous link is you can allow users to locate the post they want from the page titles faster, without the clutter of the body content, or teaser-text?
Thanks,
L
Correction:
<?php
$cats = '';
// if page is faq/blog page
if (is_page('6')) {
$cats = 'cat=5,6';
}
// if page is case studies page
elseif (is_page('7')) {
$cats = 'cat=7';
}
// query appropriate category content
if ($cats) {
query_posts($cats);
}
?>
Gives me control over how many posts are displayed (I’m sure there’s a more efficient way of doing it):
<?php
$cats = '';
// specify how many posts to show
$noPosts = 2;
// if page is faq/blog page
if (is_page('6')) {
$cats = 'cat=5,6';
$cats = $cats . '&' . 'posts_per_page=' . $noPosts;
}
// if page is case studies page
elseif (is_page('7')) {
$cats = 'cat=7';
$cats = $cats . '&' . $noPosts;
}
// query appropriate category content
if ($cats) {
query_posts($cats);
}
?>
as far as your code
if (is_page('6')) {
$cats = 'cat=5,6';
$cats = $cats . '&' . 'posts_per_page=' . $noPosts;
}
// if page is case studies page
elseif (is_page('7')) {
$cats = 'cat=7';
$cats = $cats . '&' . $noPosts;
}
You are missing part of the code for page 7
$cats = $cats . '&' . $noPosts;
should be either
$cats = $cats . '&' . 'posts_per_page=' . $noPosts;
or if using the default # of pages per page
$cats = $cats;
You don’t need the paged code until the # of posts you have to display exceeds the # of posts you are displaying on one page. Then you will find that without the paged code, when you click the ‘prev posts’ link that it displays the same posts that are on the first page, over and over.
hi, i tried applying this code but it didnt work for me!
heres my website
http://www.wwww.wethebesttv.com/blog
and i’m trying to put the blog category in the blog page so whenever i select the blog category i want it to post in the blog page…here is the blog page
http://www.wethebesttv.com/blog/?page_id=10
and here’s my page.php
<?php get_header(); ?>
<style>
html,body {
background:#0D0D0D;
color:#565050;
}
</style>
<div id="page">
<div id="insidecopy">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php if (is_page(blog)) {
query_posts("cat=9");
} ?>
<div class="copycontent"><a name="read"></a>
<h2><?php the_title() ?></h2>
<p><?php the_content(''); ?></p>
</div>
<?php endwhile; else: ?>
<?php endif; ?>
<div id="altsidebar">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Page Sidebar') ) : ?>
<div class="altsideblock">
<h3>Configure Your Sidebar!</h3>
<p>To remove this message, configure your sidebar widgets throught the WordPress admin control panel.</p>
</div>
<?php endif; ?>
</div></div>
</div>
<?php get_footer(); ?>