WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Different page, same posts.. Help! (8 posts)

  1. batmick
    Member
    Posted 3 years ago #

    Hey guys,

    So here is my idea and problem. I want to create a website for my dad with one big post on top (always the latest post) and 4 smaller blog posts beneath it.

    I searched for a solution on internet, but could really find a solution. I hope you guys can help me out!

    Here is the code for the website so far:

    <?php get_header(); ?>
    
    <div id="wrap">
    
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
     query_posts('showposts=1' . $paged); ?>
    <?php $posts = get_posts('numberposts=1&offset=0'); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count1 = 0; if ($count1 == "1") { break; } else { ?>
    
        <div class="firstpost">
        	<div class="post-date"><span class="post-month"><?php the_time('M') ?></span> <span class="post-day"><?php the_time('j') ?></span></div>
            <div class="post-title">
            	<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Link to this article!"><?php the_title(); ?></a></h2>
                <span class="post-comments"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></span>
            </div>
            <div class="entry">
            	<?php the_content('Read the rest of this entry &raquo;'); ?>
            </div>
         </div>
    
    <?php $count1++; } ?>
    <?php endforeach; ?>
    
    <div id="leftmain">
    
    <?php query_posts('showposts=1' ); ?>
    <?php $posts = get_posts('numberposts=5&offset=1'); foreach ($posts as $post) : start_wp(); ?>
    <?php static $count2 = 0; if ($count2 == "4") { break; } else { ?>
    
        <div class="post">
        	<div class="post-date"><span class="post-month"><?php the_time('M') ?></span> <span class="post-day"><?php the_time('j') ?></span></div>
            <div class="post-title">
            	<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Link to this article!"><?php the_title(); ?></a></h2>
                <span class="post-comments"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></span>
            </div>
            <div class="entry">
            	<?php the_content('Read the rest of this entry &raquo;'); ?>
            </div>
         </div>
    
    <?php $count2++; } ?>
    <?php endforeach; ?>
    
        <div class="clear"></div>
    
          <div class="navigation">
         	<span class"previous-entries"><?php next_posts_link('Older Entries') ?></span>
            <span class="next-entries"><?php previous_post_link('Newer Entries') ?></span>
         </div>
    
        </div>
    
    	<div id="rightmain">
    	     <?php get_sidebar(); ?>
    	</div>
    
            <div class="clear"></div>
    
    </div>
    
    <?php get_footer(); ?>
  2. batmick
    Member
    Posted 3 years ago #

    Oh, by the way.. Here is the link to the website (http://slotracebook.com/). It has some more issues than only the one I mentioned above!

    Thanks!

  3. keesiemeijer
    moderator
    Posted 3 years ago #

    It seems to be working, what is wrong with it? I would do something like this:

    <?php get_header(); ?>
    <div id="wrap">
    <?php  $my_query = new WP_Query('posts_per_page=1'); ?>
    <?php 	while ( $my_query->have_posts() ) : $my_query->the_post() ?>
    
        <div class="firstpost">
        	<div class="post-date"><span class="post-month"><?php the_time('M') ?></span> <span class="post-day"><?php the_time('j') ?></span></div>
            <div class="post-title">
            	<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Link to this article!"><?php the_title(); ?></a></h2>
                <span class="post-comments"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></span>
            </div>
            <div class="entry">
            	<?php the_content('Read the rest of this entry »'); ?>
            </div>
         </div>
    <?php endwhile; ?>
    
    <div id="leftmain">
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
    <?php query_posts('posts_per_page=4&offset=1&paged='.$paged ); ?>
    <?php while (have_posts()) : the_post(); ?>
        <div class="post">
        	<div class="post-date"><span class="post-month"><?php the_time('M') ?></span> <span class="post-day"><?php the_time('j') ?></span></div>
            <div class="post-title">
            	<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Link to this article!"><?php the_title(); ?></a></h2>
                <span class="post-comments"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></span>
            </div>
            <div class="entry">
            	<?php the_content('Read the rest of this entry »'); ?>
            </div>
         </div>
    <?php endwhile; ?>
    
        <div class="clear"></div>
    
          <div class="navigation">
         	<span class"previous-entries"><?php next_posts_link('Older Entries') ?></span>
            <span class="next-entries"><?php previous_post_link('Newer Entries') ?></span>
         </div>
    
        </div>
    
    	<div id="rightmain">
    	     <?php get_sidebar(); ?>
    	</div>
    
            <div class="clear"></div>
    
    </div>
    <?php get_footer(); ?>
  4. batmick
    Member
    Posted 3 years ago #

    I have the problem that the posts of the front page, also appear on the second page.

    I also seem to have a problem that I can't go back with the previous_posts_link if I am on the second page.

    But the first thing is the biggest problem!

  5. keesiemeijer
    moderator
    Posted 3 years ago #

    You can do what you want with one loop, and pagination working:

    <?php get_header(); ?>
    <div id="wrap">
    <?php $counter=0; ?>
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
    <?php query_posts('posts_per_page=5&paged='.$paged ); ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php $class= 'post'; ?>
    <?php ++$counter; ?>
    <?php if($counter == 1 && !is_paged()) { $class= 'firstpost';} ?>
    <?php if(($counter == 2 && !is_paged()) || ($counter == 1 && is_paged())) {
     echo '<div id="leftmain">'."\n";
    }
    ?>
        <div class="<?php echo $class; ?>">
        	<div class="post-date"><span class="post-month"><?php the_time('M') ?></span> <span class="post-day"><?php the_time('j') ?></span></div>
            <div class="post-title">
            	<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Link to this article!"><?php the_title(); ?></a></h2>
                <span class="post-comments"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></span>
            </div>
            <div class="entry">
            	<?php the_content('Read the rest of this entry &raquo;'); ?>
            </div>
         </div>
    <?php endwhile; ?>
    
        <div class="clear"></div>
    
          <div class="navigation">
         	<span class"previous-entries"><?php next_posts_link('Older Entries') ?></span>
            <span class="next-entries"><?php previous_post_link('Newer Entries') ?></span>
         </div>
    
        </div>
    
    	<div id="rightmain">
    	     <?php get_sidebar(); ?>
    	</div>
    
            <div class="clear"></div>
    
    </div>
    <?php get_footer(); ?>
  6. batmick
    Member
    Posted 3 years ago #

    Thank you so much!

    Do you know how I can go back to the previous page from page 2? With the previous_post_link?

    That would totally make my day!

  7. keesiemeijer
    moderator
    Posted 3 years ago #

    change this:

    <div class="navigation">
         	<span class"previous-entries"><?php next_posts_link('Older Entries') ?></span>
            <span class="next-entries"><?php previous_post_link('Newer Entries') ?></span>
         </div>

    to this:

    <div class="navigation">
         	<span class="previous-entries"><?php next_posts_link('Older Entries') ?></span>
          <span class="next-entries"><?php previous_posts_link('Newer Entries') ?></span>
         </div>
  8. batmick
    Member
    Posted 3 years ago #

    Ahhh thank you sooo much!

    Everything works the way I planned!

Topic Closed

This topic has been closed to new replies.

About this Topic