• Resolved tomm3ke

    (@tomm3ke)


    Hello!

    I would like to archive some messages so that they’re only visible in the archive and don’t show up in the homepage anymore. I’ve tried making them private, but then nobody sees them.

    Example: Homepage lists 10 posts, I would like to archive 5 so only 5 show up on the Homepage. When I click the Archive tab, it should display all 10 posts.

    Thanks for your time!

Viewing 15 replies - 1 through 15 (of 24 total)
  • Thread Starter tomm3ke

    (@tomm3ke)

    Up 1

    Thread Starter tomm3ke

    (@tomm3ke)

    Where can I edit this query?

    Thread Starter tomm3ke

    (@tomm3ke)

    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?

    Thread Starter tomm3ke

    (@tomm3ke)

    UP 2

    Moderator keesiemeijer

    (@keesiemeijer)

    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(); 
    ?>

    Thread Starter tomm3ke

    (@tomm3ke)

    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 …

    Moderator keesiemeijer

    (@keesiemeijer)

    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; ?>

    Thread Starter tomm3ke

    (@tomm3ke)

    I have no clue what you’re doing there 😛 Isn’t there an easier way?

    Moderator keesiemeijer

    (@keesiemeijer)

    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.

    Thread Starter tomm3ke

    (@tomm3ke)

    I am using the TwentyEleven theme.

    http://pastebin.com/Wqfm2VM4

    Moderator keesiemeijer

    (@keesiemeijer)

    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

    Thread Starter tomm3ke

    (@tomm3ke)

    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);
                            ?>

    Moderator keesiemeijer

    (@keesiemeijer)

    change it to 'cat' => -4, // category ID you want to exclude
    if you want to exclude all category 4 posts on the second loop.

    Thread Starter tomm3ke

    (@tomm3ke)

    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!!

Viewing 15 replies - 1 through 15 (of 24 total)
  • The topic ‘Display items in archive, but not on homepage’ is closed to new replies.