Where can I edit this query?
UP 1
if (is_category(‘sports’)):
query_posts(array(‘Sports’ => ‘sports’, ‘posts_per_page’ => 1 ));
endif;
This should only show 1 post per page, for the category sports? I presume the newest post. Where would I insert this code?
Try it with this in your themes index.php just before the loop:
$args = array(
'cat' => -12, // category ID you want to exclude
'posts_per_page' => 5
);
query_posts($args);
Change “-12” to the category ID you want to exlude.
The loop starts with something simular to this (depending on your theme):
<?php
// The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
Ok, I found out where I need to do it. But your code completely excludes the category. I only want to show the newest post from category 1 and all the other posts from other categories.
Homepage: Cat 1 Post – Cat 2 Post – Cat 2 Post – Cat 2 Post – Cat 3 Post …
Try it with multiple loops. Here is a simplified version of what you want:
<?php $my_query = new WP_Query('cat=1&posts_per_page=1'); ?>
<?php /* Start of first the Loop */ ?>
<?php while ($my_query->have_posts()) : $my_query->the_post();?>
<!-- rest of your loop -->
<?php endwhile; ?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'cat' => -1, // category ID you want to exclude
'posts_per_page' => 5,
'paged' => $paged
);
query_posts($args); ?>
<?php /* Start of second the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<!-- rest of your loop -->
<?php endwhile; ?>
I have no clue what you’re doing there 😛 Isn’t there an easier way?
What theme are you using?
Can you paste the content of your index.php in a pastebin, submit it and post a link to it back here.
I am using the TwentyEleven theme.
http://pastebin.com/Wqfm2VM4
if you are using the default theme it is better to create a child theme for these changes.
try it with this index.php: http://pastebin.com/vc5uDMCV
Works like a charm! I don’t really understand it though, Category 1 is my category that only shows 1 post and Category 4 contains the rest.
This is how I read it, Category 4 show 1 post, then next loop exclude Category 1. Or am I reading it wrong?
<?php twentyeleven_content_nav( 'nav-above' ); ?>
<?php $my_query = new WP_Query('cat=4&posts_per_page=1'); ?>
<?php /* Start of first the Loop */ ?>
<?php while ($my_query->have_posts()) : $my_query->the_post();?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'cat' => 1, // category ID you want to exclude
'posts_per_page' => 5,
'paged' => $paged
);
query_posts($args);
?>
change it to 'cat' => -4, // category ID you want to exclude
if you want to exclude all category 4 posts on the second loop.
No, I mean it works the way I posted it there. But I don’t understand why.
('cat=4&posts_per_page=1')
I would expect this mean show 1 post per page for category 4. But what it does is, show only the first post for Category 1!!