I wrote this code, but when I set the page where I write this code as a posts page from the dashboad, then viewed it on the browser. it has become empty, although I puplished one post. what is wrong with this code, please?

         if (have_posts()) : 
            while (have_posts()): the_post(); ?>

                 <div class="col-md-7 col-lg-8">

                         <div class="mb-50 mb-sm-30">
                                 <div class="pos-relative mb-30 pt-15">
                                         <div class="font-8 abs-tl p-20 bg-primary color-white">
                                                 <?php if(has_post_thumbnail()) : ?>

                      <img src="<?php the_post_thumbnail_url(); ?>" alt="">
                      <?php endif; ?>

              <h4><a href="<?php the_permalink(); ?>"><b> <?php the_title(); ?> </b></a></h4>
              <h6 class="mt-10 bg-lite-blue dplay-inl-block">
                      <a class="plr-20 mtb-10" href="#"><b>By <?php the_author_posts_link(); ?></b></a>
                      <a class="plr-20 mtb-10 brder-lr-lite-black-2" href="#"><b>in <?php the_category( ', ' ); ?></b></a>
                      <a class="plr-20 mtb-10" href="#"><b> <?php comments_popup_link('0 comments'); ?> </b></a>
              <p class="mt-30"> <?php the_excerpt(); ?> </p>
        <?php   endwhile;
           endif; ?>

  • in what file did you save that code? is that the code for a custom page template? most likely, that page is not used for your 'posts page' bacause the 'posts page' is ususally rendered by index.php or home.php; developer.wordpress.org/themes/basics/template-hierarchy/… – Michael May 24 '20 at 19:49
  • thanks for reply. this code in file called blog.php and I set it as posts page from the dashboard – social May 24 '20 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.