0

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!

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.