• Resolved streetrose

    (@streetrose)


    I have been coding themes for the past years but I’m not really an expert in php. I hope someone can help me about this problem:

    I have four loops in index.php

    1st: featured category posts carousel (which is already working way before)

    2nd: Certain cat post, 1 post_per_page, with additional class in most parent div

    3rd: Certain cat posts, 2 post_per_page, with additional class in most parent div

    4th: The rest of the posts, with additional class in most parent divs, hould do_not_duplicate posts from above category except for featured

    then I want the 4th loop to be paginated — like page/2/ will show the next page of the rest of the posts (aka recent posts) in the 4th loop.

    Here is my code

    <!-- start content -->
    <div id="content">
    	<?php if(is_home() && !is_paged()): ?>
        <?php // Featured posts go here.
        include (TEMPLATEPATH . "/featured.php"); ?>
        <?php endif;?>
        <?php if(is_home() && !is_paged()): ?>
        <div id="highlightcat1">
        	<h3 class="head">Latest Projects <a title="More Projects Updates" href="https://ygladies.com/category/ygladies/projects">more+</a></h3>
    		<?php if( $themesbyrozeh_settings['highlighted_cat1'] ) : ?>
            <?php query_posts('posts_per_page=1&cat=' . $themesbyrozeh_settings['highlighted_cat1'] ); ?>
            <?php while (have_posts()) : the_post(); ?>
            <?php $do_not_duplicate[] = $post->ID; ?>
        	<div class="post ptop red">
                <div class="feat">
                    <?php
                    // Must be inside a loop.
    
                    if ( has_post_thumbnail() ) {
                        the_post_thumbnail('ptop');
                    }
                    else {
                    // nothing here
                    }
                    ?>
                    <span class="date"><?php the_time('d F y') ?></span>
                </div>
                <div class="entry">
                        <div class="entryinfo">
                            <?php edit_post_link('Edit', '<span class="edit">', '</span> -'); ?> <span class="author"><?php the_author() ?></span> - <span class="sdate"><?php the_time('d/m/y') ?></span> - <span class="comment_count"><?php comments_popup_link('0 Comments', '1 Comment', '% Comments'); ?></span>
                            <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                        </div>
                        <p><?php echo limit_words(get_the_excerpt(), '30'); ?>.</p>
                        <a class="readmore" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">Read More &rarr;</a>
                </div>
            </div>
            <?php endwhile; ?>
            <?php endif; ?>
            <?php wp_reset_query(); ?>
        </div>
        <?php endif;?>
    
        <?php if(is_home() && !is_paged()): ?>
        <div id="highlightcat2">
        	<h3 class="head">Latest SNS Updates <a title="More SNS Updates" href="https://ygladies.com/category/snsupdates">more+</a></h3>
    		<?php if( $themesbyrozeh_settings['highlighted_cat2'] ) : ?>
            <?php query_posts('posts_per_page=2&cat=' . $themesbyrozeh_settings['highlighted_cat2'] ); ?>
            <?php while (have_posts()) : the_post(); ?>
            <?php
            $extra_classes = array('orange','green','blue','indigo','violet','pink','red');
            $extra_class = $extra_classes[$wp_query->current_post%count($extra_classes)];
            ?>
            <?php $do_not_duplicate[] = $post->ID; ?>
        	<div class="post ptop2 <?php echo $extra_class; ?> clearfix">
                <div class="feat">
                    <?php
                    // Must be inside a loop.
    
                    if ( has_post_thumbnail() ) {
                        the_post_thumbnail();
                    }
                    else {
                    // nothing here
                    }
                    ?>
                    <span class="date"><?php the_time('d F y') ?></span>
                </div>
                <div class="entry">
                        <div class="entryinfo">
                            <?php edit_post_link('Edit', '<span class="edit">', '</span> -'); ?> <span class="author"><?php the_author() ?></span> - <span class="comment_count"><?php comments_popup_link('0 Comments', '1 Comment', '% Comments'); ?></span>
                            <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                        </div>
                        <p><?php echo limit_words(get_the_excerpt(), '30'); ?>.</p>
                        <a class="readmore" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">Read More &rarr;</a>
                </div>
            </div>
            <?php endwhile; ?>
            <?php endif; ?>
            <?php wp_reset_query(); ?>
        </div>
    	<?php endif;?>
        <h3 class="head">Recent Posts</h3>
        <div id="entries" class="clearfix">
    		<?php query_posts(array('post__not_in'=>$do_not_duplicate));
    		 if (have_posts()) : while (have_posts()) : the_post();
    		 ?> 
    
    		<?php
            $extra_classes = array('blue','indigo','violet','pink','red','orange','green');
            $extra_class = $extra_classes[$wp_query->current_post%count($extra_classes)];
            ?>
    
            <!-- start entry post -->
            <div class="post pfloat <?php echo $extra_class; ?>" id="post-<?php the_ID(); ?>">
                <div class="entry">
                    <div class="feat">
    					<?php
                        // Must be inside a loop.
    
                        if ( has_post_thumbnail() ) {
                            the_post_thumbnail();
                        }
                        else {
                        // nothing here
                        }
                        ?>
                        <span class="date"><?php the_time('d F y') ?></span>
                    </div>
                    <div class="entryinfo">
                        <?php edit_post_link('Edit', '<span class="edit">', '</span> -'); ?> <span class="author"><?php the_author() ?></span> - <span class="comment_count"><?php comments_popup_link('0 Comments', '1 Comment', '% Comments'); ?></span>
                        <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                    </div>
                    <p><?php echo limit_words(get_the_excerpt(), '30'); ?>.</p>
                </div>
            </div>
            <!-- end entry post -->
    
            <?php endwhile; ?>
            <?php else : ?>
    
            <div class="post">
                <div class="entry">
                    <h2>Not Found</h2>
                    Sorry, but you are looking for something that isn't here.
                </div>
            </div>
    
            <?php endif; ?>
            <?php wp_reset_query(); ?>
        </div>
        <div id="pagi">
            <?php previous_posts_link('&larr; Previous') ?><?php rozehtheme_pagination(); ?><?php next_posts_link('Next &rarr;') ?>
        </div>
    </div>
    <!-- end content -->

    I thought I made it work (the classes are there and there are no duplicate posts but when I went to page/2/, it’s displaying the same posts in loop 4.

    I hope anyone can help me here. I will forever be grateful. ??

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Multiple Loops Additional classes Pagination help’ is closed to new replies.