• Resolved tecnosh

    (@tecnosh)


    Hello.
    I have a website http://www.Tecnosh.com thats use a Quo theme. I already change a lot the theme but stills with one big problem.

    The theme list on bottom the last 5 posts from 6 categorys.. and on top list the last 8. What I need and appreciated a lot some help is if exist any way to remove that last 8 post from the bottom categories.. do prevent duplicated content.

    Ex: If the last post is in Category: Gadgets will show on top.. and at the same time on bottom on Gadgets Column. Any one can help me?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    What is the code that generates the top list of posts (the Loop) and the code that generates the bottom list (a different Loop)?

    Basically, you need to save the top list of posts and then exclude those from the bottom list. This isn’t hard, but it depends on the layout of your Loop.

    Thread Starter tecnosh

    (@tecnosh)

    Hei Otto. Thanks for your help man.

    First loop that show the last 8 posts:

    <?php get_header(); ?>
    <div id="content" class="container">
    <div id="front" class="column_main">
     	<?php query_posts('showposts=8'); ?>
    	<?php while (have_posts()) : the_post(); ?>
    <h1><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>

    And the loop that are repeated 6 times for the 6 diffrent categories is:

    <div class="column_left_b"> <!-- The 1st of the 3 columns with the featured articles at the bottom left -->
    <?php query_posts('showposts=1&cat=3'); ?> <!-- Edit the cat= part to the number of the desired category (check the category IDs in your WordPress system), and this will show the 1st of the chosen category -->
    <?php while (have_posts()) : the_post(); ?>
    <h2><?php the_category(', '); ?><i> - <?php the_time('M j, Y G:i'); ?> - <a href="<?php the_permalink() ?>#commenting" title="Ir para Comentários."><?php comments_number('0 Comentários','1 Comentário','% Comentários'); ?></a></i></h2>
    <h1><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>
    Thread Starter tecnosh

    (@tecnosh)

    The hard part is that the 6 bottom categories loops have to see if any of the 8 last posts are in her categories, if its true exclude that post and get the last-last one.

    Sounds weird?

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Heh. I get what you’re saying, but you’re thinking of it the hard way.

    1. In your first loop, we have to save the post ID’s. We do that like this:

    ...
    <?php
    query_posts('showposts=8');
    $saved_ids = array();
    while (have_posts()) : the_post();
    $saved_ids[] = get_the_ID();
    ?>
    ... blah blah...

    2. In your second loop, we need to exclude those posts entirely. To do that, we’ll use a different method for query_posts than you may be familiar with. Instead of <?php query_posts('showposts=1&cat=3'); ?>, use this:

    <?php
    query_posts(array(
    'showposts' => 1,
    'cat' => 3,
    'post__not_in' => $saved_ids,
    ));
    ?>

    The post__not_in parameter excludes a list of posts (in this case, an array of post ID’s) from the results. We have to use the special method of calling query_posts because we cannot pass an array as a string easily.

    Note that the post__not_in is relatively new. I know that it is definitely in 2.6, I don’t know if it works in 2.5.1 or not.

    Thread Starter tecnosh

    (@tecnosh)

    Hm, it works but in the reverse way.. at the bottom loop the only one that appear in that categorie is the duplicated.

    Will search if the cause its wordpress 2.5. Haven’t download 2.6 yet.

    Thread Starter tecnosh

    (@tecnosh)

    you know any way do to this without that new parameter?

    Thread Starter tecnosh

    (@tecnosh)

    Tested on 2.6 and it works. Thanks Otto.

    I’m also running 2.6 and have across the exact same difficulty. I’m wondering if either of you can assist me in a fix for my site. From the looks of it, it seems like you’ve found a solution. I’m kind of a beginner to this so I don’t fully understand it.

    Thanks.

    Thread Starter tecnosh

    (@tecnosh)

    sammy, just ask man.

    Otto, how I get the post ID instant of query_posts(‘showposts=8’); ?
    I ask that because on the post (single.php) i have 3 categorys listing 5 posts too.. and would like to not duplicated on post.

    one more time, many thanks man.

    Yes!!! thank, thank you!!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Prevent Duplicate Content’ is closed to new replies.