Do not duplicate posts with Genesis and Custom Loop

Community Forums Forums Design Tips and Tricks Do not duplicate posts with Genesis and Custom Loop

This topic is: not resolved

Tagged: ,

This topic contains 1 reply, has 2 voices, and was last updated by  Susan 3 months, 2 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #112974

    Yeltsin Lima
    Member
    Post count: 5

    I’m using the Sample Child Theme to create a website for my client. But I do need some help.

    I created a page called home.php and I’m showing this code (It’s a big code):

    <?php get_header(); ?>
    
        <!-- slider -->
        <div class="container">
    
            <div class="row">
    
                <div class="col-md-8">
    
                    <div class="row">
    
                        <div class="col-md-12 hidden-sm hidden-xs">
    
                            <?php putRevSlider("home-slider","homepage") ?>
    
                        </div>
    
                    </div>
    
                    <div class="row">
    
                        <div class="col-md-12 cat-name">
                            <p><span class="label label-primary">Reflexões</span></p>
                        </div>
    
                        <?php $categoria_home_um = new WP_Query('category_name=reflexoes&posts_per_page=3'); ?>
                        <?php while ($categoria_home_um->have_posts()) : $categoria_home_um->the_post(); $do_not_duplicate = $post->ID; ?>
                        <div class="col-md-4 col-sm-4">
                            <div class="thumbnail">
                                <?php 
                                if ( get_the_post_thumbnail($post_id) != '' ) {
    
                                  echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
                                   the_post_thumbnail( 'home-images' );
                                  echo '</a>';
    
                                } else {
    
                                 echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
                                 echo '<img class="img-responsive" src="';
                                 echo catch_that_image();
                                 echo '" alt="" />';
                                 echo '</a>';
    
                                }
                                ?>
                                <div class="caption">
                                    <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                                </div>
                            </div>
                        </div>
                        <?php endwhile;?>
    
                        <div class="col-md-12 cat-name">
                            <p><span class="label label-primary">Atitude</span></p>
                        </div>
    
                        <?php $categoria_home_dois = new WP_Query('category_name=atitude&posts_per_page=3'); ?>
                        <?php while ($categoria_home_dois->have_posts()) : $categoria_home_dois->the_post(); $do_not_duplicate = $post->ID; ?>
                        <div class="col-md-4 col-sm-4">
                            <div class="thumbnail">
                                <?php 
                                if ( get_the_post_thumbnail($post_id) != '' ) {
    
                                  echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
                                   the_post_thumbnail( 'home-images' );
                                  echo '</a>';
    
                                } else {
    
                                 echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
                                 echo '<img class="img-responsive" src="';
                                 echo catch_that_image();
                                 echo '" alt="" />';
                                 echo '</a>';
    
                                }
                                ?>
                                <div class="caption">
                                    <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                                </div>
                            </div>
                        </div>
                        <?php endwhile;?>
    
                        <div class="col-md-12 cat-name">
                            <p><span class="label label-primary">Comportamento</span></p>
                        </div>
    
                        <?php $categoria_home_tres = new WP_Query('category_name=comportamento&posts_per_page=3'); ?>
                        <?php while ($categoria_home_tres->have_posts()) : $categoria_home_tres->the_post(); $do_not_duplicate = $post->ID; ?>
    
                        <div class="col-md-4 col-sm-4">
                            <div class="thumbnail">
                                <?php 
                                if ( get_the_post_thumbnail($post_id) != '' ) {
    
                                  echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
                                   the_post_thumbnail( 'home-images' );
                                  echo '</a>';
    
                                } else {
    
                                 echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
                                 echo '<img class="img-responsive" src="';
                                 echo catch_that_image();
                                 echo '" alt="" />';
                                 echo '</a>';
    
                                }
                                ?>
                                <div class="caption">
                                    <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                                </div>
                            </div>
                        </div>
                        <?php endwhile;?>
    
                    </div>
    
                    <div class="row">
    
                        <div class="col-md-12">
    
                            <?php genesis_standard_loop(); ?>
    
                        </div>
    
                    </div>
    
                </div>
    
                <div class="col-md-4">
                    <?php get_sidebar(); ?>
                </div>
    
            </div>
    
        </div>
    
    <?php get_footer(); ?>

    As you can see I’m repeating three loops. The only difference is the “category_name”. EDIT: I was able to solve the first part of my “error” using this article.

    But I also need to remove the post from the “big loop” (the Genesis Loop). So the post needs to appear only one time (It can shows “freely” on Recent Posts widget but not in the main loop).

    So see the new home.php using the markup from the other article:

    <?php get_header(); ?>
    
        <!-- slider -->
        <div class="container">
    
            <div class="row">
    
                <div class="col-md-8">
    
                    <div class="row">
    
                        <div class="col-md-12 hidden-sm hidden-xs">
    
                            <?php putRevSlider("home-slider","homepage") ?>
    
                        </div>
    
                    </div>
    
                    <div class="row">
    
                        <div class="col-md-12 cat-name">
                            <p><span class="label label-primary">Reflexões</span></p>
                        </div>
    
                        <?php   $do_not_duplicate = array(); ?>
                        <?php   $mosaics = new WP_Query('category_name=reflexoes&posts_per_page=3'); ?>
                        <?php   while ($mosaics->have_posts()) : $mosaics->the_post(); ?>
                        <?php   $do_not_duplicate[] = $post->ID; ?>
                        <div class="col-md-4 col-sm-4">
                            <div class="thumbnail">
                                <?php 
                                if ( get_the_post_thumbnail($post_id) != '' ) {
    
                                  echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
                                   the_post_thumbnail( 'home-images' );
                                  echo '</a>';
    
                                } else {
    
                                 echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
                                 echo '<img class="img-responsive" src="';
                                 echo catch_that_image();
                                 echo '" alt="" />';
                                 echo '</a>';
    
                                }
                                ?>
                                <div class="caption">
                                    <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                                </div>
                            </div>
                        </div>
                        <?php   endwhile; wp_reset_postdata(); ?>
    
                        <div class="col-md-12 cat-name">
                            <p><span class="label label-primary">Atitude</span></p>
                        </div>
    
                        <?php   $mosaics = new WP_Query( array( 'category_name' => 'atitude', 'posts_per_page' => 3, 'post__not_in' => $do_not_duplicate ) ); ?>
                        <?php   while ($mosaics->have_posts()) : $mosaics->the_post(); ?>
                        <?php   $do_not_duplicate[] = $post->ID; ?>
                        <div class="col-md-4 col-sm-4">
                            <div class="thumbnail">
                                <?php 
                                if ( get_the_post_thumbnail($post_id) != '' ) {
    
                                  echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
                                   the_post_thumbnail( 'home-images' );
                                  echo '</a>';
    
                                } else {
    
                                 echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
                                 echo '<img class="img-responsive" src="';
                                 echo catch_that_image();
                                 echo '" alt="" />';
                                 echo '</a>';
    
                                }
                                ?>
                                <div class="caption">
                                    <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                                </div>
                            </div>
                        </div>
                        <?php   endwhile; wp_reset_postdata(); ?>
    
                        <div class="col-md-12 cat-name">
                            <p><span class="label label-primary">Comportamento</span></p>
                        </div>
    
                        <?php   $mosaics = new WP_Query( array( 'category_name' => 'comportamento', 'posts_per_page' => 3, 'post__not_in' => $do_not_duplicate ) ); ?>
                        <?php   while ($mosaics->have_posts()) : $mosaics->the_post(); ?>
                        <?php   $do_not_duplicate[] = $post->ID; ?>
    
                        <div class="col-md-4 col-sm-4">
                            <div class="thumbnail">
                                <?php 
                                if ( get_the_post_thumbnail($post_id) != '' ) {
    
                                  echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
                                   the_post_thumbnail( 'home-images' );
                                  echo '</a>';
    
                                } else {
    
                                 echo '<a href="'; the_permalink(); echo '" class="thumbnail-wrapper">';
                                 echo '<img class="img-responsive" src="';
                                 echo catch_that_image();
                                 echo '" alt="" />';
                                 echo '</a>';
    
                                }
                                ?>
                                <div class="caption">
                                    <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                                </div>
                            </div>
                        </div>
                        <?php   endwhile; wp_reset_postdata(); ?>
    
                    </div>
    
                    <div class="row">
    
                        <div class="col-md-12">
    
                            <?php genesis_standard_loop(); ?>
    
                        </div>
    
                    </div>
    
                </div>
    
                <div class="col-md-4">
                    <?php get_sidebar(); ?>
                </div>
    
            </div>
    
        </div>
    
    <?php get_footer(); ?>

    Great, but the <?php genesis_standard_loop(); ?> still shows the post (duplicated). How can I fix this thing.

    By the way: any suggestion to improve the markup of the code? :)

    Thanks.


    I’m not from StudioPress, I just like to help people! :)

    http://www.simplescoisasdavida.com/
    #117326

    Susan
    Moderator
    Post count: 9406

    As you posted this over a month ago, I hope your issue was resolved. If not, check back in, and I will escalate.

    Thanks!


    Susan @ Graphically Designing I offer theme customizations I tweet!
    I’ve taken up the challenge! – help me answer some of the unanswered posts

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.