• I’m trying to make a template and I’d like to show the first 10 posts at the main column and the show the 10 older at the sidebar. At the main, I have:

    <?php if ( have_posts() ) : ?>
                        <div class="content">
    
                            <?php while ( have_posts() ) : the_post(); ?>
                                <div class="article list">
    
                                    <a href="<?php the_permalink(); ?>"><img src="<?=catch_that_image(); ?>"></a>
                                    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                                    <div class="caption"><span class="date"><?php the_time('j F, Y'); ?></span>&nbsp;&nbsp;|&nbsp;&nbsp;
                                        <a href="<?php the_permalink(); ?>#comments">
                                            <?php comments_number('No comments', '1 comment', '% comments'); ?>
                                        </a>
                                    </div>
                                    <div class="txt">
                                        <?php the_excerpt(); ?>
                                    </div>
                                </div>
                                <?php endwhile; ?>
                        </div>
                        <?php endif; ?>

    And at the sidebar I have:

    <?php if ( have_posts() ) : ?>
    
            <?php 
    
    		$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    		$offset = ($paged * get_option('posts_per_page'));
    		$args = array (
    				'paged' =>$paged,
    				'posts_per_page' => get_option('posts_per_page'),
    				'offset' => $offset
    			);
    		get_posts($args);
    
    		?>
    
                <?php while ( have_posts() ) : the_post(); ?>
                    <div class="article">
                        <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                        <div class="caption"><span class="date"><?php the_time('j F, Y'); ?></span>&nbsp;&nbsp;|&nbsp;&nbsp;
                            <a href="<?php the_permalink(); ?>#comments">
                                <?php comments_number('No comments', '1 comment', '% comments'); ?>
                            </a>
                        </div>
                        <div class="txt">
                            <?php the_excerpt(); ?>
                        </div>
                    </div>
                    <?php endwhile; ?>
    
                        <?php endif; ?>

    Does anybody what I’m making wrong? Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • If sidebar comes before main content? => try reset query
    https://codex.wordpress.org/it:Riferimento_funzioni/wp_reset_query

    otherwise, what happens now that you say is wrong? What’s the output?

    Thread Starter pezcore

    (@pezcore)

    The sidebar goes after the main content. I tried to use the reset query, but it doesn’t work. It shows me the same posts than in the main content…

    If you var_dump($args); just before sidebar get_posts($args);, what’s the output (just var_dump() output)?

    I think that ‘posts_per_page’ and ‘offset’ must have an integer always set.

    Thread Starter pezcore

    (@pezcore)

    The output is:
    array(3) { ["paged"]=> int(1) ["posts_per_page"]=> string(2) "10" ["offset"]=> int(10) }

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get 10 posts at main and 10 older at sidebar’ is closed to new replies.