WordPress showing post info under new pages, but I want it to show only under new posts

I have basic loop to show PHP posts

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

      <div class="post">
                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                <div class="post-info"><?php echo get_the_date(); ?> - posted by <?php echo get_the_author(); ?> </a></div>

                <?php the_content('<button class="show-more">Saznajte više</button>'); ?>
            </div>

    <?php
      endwhile;
      else :
      echo "<p>No posts</p>";
  endif;

It is the line that has <div class="post-info...
Now it is working very well, it shows date and author under post heading, but it also shows that when a new page is created. I understand WordPress works like blog and it is natural for it to treat new pages as posts, however I want to avoid that behavior. I only want it to be shown under post headings, but not under new page headings. What would you suggest me?

Related posts

1 comment

  1. https://developer.wordpress.org/themes/basics/template-hierarchy/

    Check this template hierarchy and you’ll understand how WordPress call template files.

    Basically, WordPress firstly runs index.php and then call different template files. Since you only have index.php, so when rendering pages it all also falls back to index.php.

    What you can do is creating a page.php with its own design for WordPress to call properly.

Comments are closed.