• Hey guys,

    I run the website https://everydaygamers.com. My problem is that my posts are duplicating on the main page. It’s kind of complicated to explain what the exact problem is but I will try…

    If you visit the site you will see that I have a featured section which shows 5 posts, a latest podcasts section that shows 3 posts, a reviews section that shows 5 posts and a news section that shows 5 posts. I want to show articles from all of those categories in the “latest articles” section but I don’t want them to duplicate. Offsetting doesn’t work because it only offsets 5 posts from all categories, not specific categories.

    What I’d like to do is be able to throw in some code that tells it not to duplicate any posts on the main page.

    Is this possible?

    If it’s not possible then is it possible to offset individual categories? I’d rather not do this but it could be a temporary fix.

    Thanks for your time.

Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter CrownOfThornz

    (@crownofthornz)

    At the time of writing my website keeps getting a 500 Internal Server Error. Hopefully you guys understand my problem without checking out the website.

    Thread Starter CrownOfThornz

    (@crownofthornz)

    My website is working now without the error so you guys can see what I mean.

    Again, my problem is that on the front page I have 5 review post, 5 news posts, and 5 featured articles…

    On that same front page I have a “latest articles” section in which I want to show and combine all posts from all categories. I can do this but then it shows the same reviews, news, and featured articles that are already on the main page.

    Offsetting doesnt work because it only offsets the combined categories. I’d like to offset the reviews category by 5, the news category by 5, and the featured category by 5.

    Or, if its possible, just throw in a code that says not to duplicate posts on the main page.

    Am I clear when I explain this?

    For each of your loops you would need to maintain a list or array of the posts that already displayed then use that list to exclude (or filter) on subsequent loops.

    Probably better to direct you to:
    https://www.google.com/search?q=wordpress+avoid+display+duplicate+posts

    [edit link]

    you could track the already shown posts in an array and the use ‘post__not_in’ :

    https://codex.www.ads-software.com/Template_Tags/query_posts#Post_.26_Page_Parameters

    ‘post__not_in’ => array(6,2,8) – exclusion, lets you specify the post IDs NOT to retrieve

    also check: https://codex.www.ads-software.com/The_Loop#Multiple_Loops_in_Action

    if you copy your file into a pastebin and post the link here, someone might have a closer look at it ??

    Thread Starter CrownOfThornz

    (@crownofthornz)

    Lets say my reviews “loop” is in functions.php and my “latest articles” loop is in index.php would that work?

    Or do they have to be in the same file.

    I am not the best at code, I am teaching myself so 50% of this is over my head.

    Thread Starter CrownOfThornz

    (@crownofthornz)

    Below is the code for my latest articles, this is located on index.php. I want to have all posts from all categories here but with the offset of 5 for news, reviews, and featured.

    <!-- Latest Articles // -->
    		<span class="heading2"><span><?php echo $_GET['paged'] ? 'Page'.$_GET['paged'] : 'Latest Articles'; ?></span></span>
    		<ul class="articles">
                <?php while (have_posts()) : the_post(); ?>
                <li id="post-<?php the_ID(); ?>">
    				<a class="title" href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    				<span class="pinfo">
    					<a class="comments" href="<?php the_permalink() ?>#comments"><?php comments_number(__('0'), __('1'), __('%')); ?> Comments</a>Posted by <?php the_author_posts_link() ?> on <?php the_date(); ?> under <span><?php the_category(', ') ?></span>
    				</span>
    				<?php if(get_post_meta($post->ID, "thumbnail", true)) : ?>
    					<a href="<?php the_permalink(); ?>" class="thumb"><img src="<?php echo get_post_meta($post->ID, "thumbnail", true); ?>" /></a>
    				<?php endif; ?>
    				<div class="post">
    					<?php wpn_content_limit(get_the_content(),400); ?> <a href="<?php the_permalink(); ?>">more</a>.
    				</div>
    				<div class="clear"></div>
    			</li>
    		<?php endwhile; ?>
    		</ul>
    		<!-- // Latest Articles -->

    Here for example is the code for the news section of the main page, this code is located in functions.php

    class widget_wpn_latestp extends WP_Widget {
    		/** constructor */
    		function widget_wpn_latestp() {
    			parent::WP_Widget(false, $name = 'WP Now: Latest Previews');
    		}
    
    		/** @see WP_Widget::widget */
    		function widget($args, $instance) {
    			extract( $args );
    			global $wpdb,$post;
    			$latestp = new WP_Query("cat=1623,1630,1627,1624,1655,1656,1657&showposts=".$instance['limit']);
    			?>
    				<!-- Latest Previews // -->
    				<span class="heading2"><span><?php echo $instance['title']; ?></span></span>
    				<div class="box">
    					<ul class="latestrp">
    					<?php if($latestp->have_posts()) : ?>
    						<?php while($latestp->have_posts()) : $latestp->the_post();?>
    						<li>
    							<?php if(get_post_meta($post->ID, "thumbnail_small", true)) : ?>
    								<img src="<?php echo get_post_meta($post->ID, "thumbnail_small", true); ?>" />
    							<?php endif; ?>
    							<a href="<?php the_permalink(); ?>"><?php echo wpn_content_limit(get_the_title(),35); ?></a>
    							<span>Posted Under: <?php the_category(', '); ?></span>
    						</li>
    						<?php endwhile; ?>
    					<?php else: ?>
    						<li>No posts found</li>
    					<?Php endif; ?>
    					</ul>
    				</div>
    Thread Starter CrownOfThornz

    (@crownofthornz)

    What if I want it to be automatic. It seems like I have to know the post ID’s. I only want it to offset, so it changes each time I post a new article.

    the loop ‘knows’ the post IDs ($post->ID); all you need to do is to put the code into the right place to gather these IDs, while the posts are getting displayed in the loop(s); and the information for that is in the links a gave you (from the codex).
    how to use the array with the already posted posts, to exclude them in the last loop, is also described in the links.

    Thread Starter CrownOfThornz

    (@crownofthornz)

    So I put the first loop code where I want it to gather the information… then I put the second loop code where I want it to not show that information?

    I will read over you links but from what I skimmed over, it seems over my head. Like I said, I am teaching myself but it’s usually trial and error kind of coding for me.

    Thread Starter CrownOfThornz

    (@crownofthornz)

    Alchymyth,

    I’ve read through the links you gave me. I’m going to give it a try and I will post my results here.

    Thanks.

    Thread Starter CrownOfThornz

    (@crownofthornz)

    I’ve been messing around but nothing seems to work.

    I put the first loop code into where it my featured posts are showing, this happens to be in header.php.

    I put the second loop code into where my latest articles are showing, where I want to not show duplicate featured posts, which is in index.php.

    Nothing happens.

    I may be doing it totally wrong. If you guys could look at the two codes that I pasted above maybe you could show me how to insert the loops as specified in alchymyth’s links (the codex).

    Thread Starter CrownOfThornz

    (@crownofthornz)

    I am having no luck with these loops. Is it possible to offset one category at a time? Like offset category #1 by 5 and then offset category #2 by 3 and offset category #3 by 10…

    Those are just examples.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Need Help Not Duplicating Posts on Main Page’ is closed to new replies.