Winterwind
Winterwind

Reputation: 117

Wordpress post loop

So im trying to add a function called "latest posts" in a sidebar section.

This is how my code looks like in sidebar.php-file.

  <?php

            query_posts('category = all');

    if (have_posts()) :

       while (have_posts()) : ?>

             <?php the_post();
          the_excerpt(); ?>


             <p class="datum2"><?php the_time('Y-m-d'); ?></p>
             <p class="Nyhetsrubrik3"><a style="orange"; href="<?php the_permalink() ?>" ><?php the_title(); ?></a></p>
                  <p class="textnyhet2">

       </p>


      <?php endwhile;
      endif;
    ?>

My problem is, no matter how much I move around in the code I just cant seems to get the correct title/date to appear above the correct post.

Now it's like the post comes first, then right under the post the date and title appears above another incorrect post etc.

Example:

Latest post text

space---->

title/date, (though to the post above)

latest post text

space----->

and continue like that.

Would be grateful if anyone could help me out.

Thanks!

Upvotes: 0

Views: 42

Answers (1)

Howli
Howli

Reputation: 12469

The reason the title/date appears below the post is because that's the way you have specified it to appear. Change

<?php the_post();
      the_excerpt(); ?>


         <p class="datum2"><?php the_time('Y-m-d'); ?></p>
         <p class="Nyhetsrubrik3"><a style="orange"; href="<?php the_permalink() ?>" ><?php the_title(); ?></a></p>
              <p class="textnyhet2">

   </p>

to

<?php the_post(); ?>

         <p class="datum2"><?php the_time('Y-m-d'); ?></p>
         <p class="Nyhetsrubrik3"><a style="orange"; href="<?php the_permalink() ?>" ><?php the_title(); ?></a></p>

     <?php the_excerpt(); ?>
              <p class="textnyhet2">

   </p>

It should display the way you want it.

the_excerpt(); is printing out an excerpt of the post, then the time/title displays. Now it should display the time and title first, then display the excerpt of the post.

Upvotes: 2

Related Questions