1

I have placed the following Blog Loop into my 'index.php' file:

<?php
    if ( have_posts() ):
        while( have_posts() ): the_post(); 
?>
    <h3><?php the_title(); ?></h3> 
    <p><?php the_content(); ?></p>
    <small>This entry was posted on: <?php the_date('l, jS F Y'); ?> at <?php the_time('g:i a'); ?> and is filed under <?php the_category(); ?></small>

    <?php 
            endwhile;
        endif;
    ?>

On my Home page, the above code does not call any Blog Posts as I have appointed a 'Blog' page for my Blogs. That said, the above <small>This entry was posted on: <?php the_date('l, jS F Y'); ?> at <?php the_time('g:i a'); ?> and is filed under <?php the_category(); ?></small> is appearing on my Home page as well as other pages. I realise that this is because I have hard coded it into my index.php but how do I remove this. If I simply remove it from my code, it does not appear on my appointed Blog page.

Any suggestions?

2 Answers 2

1

what about surrounding it in the if is_home() statement so it only shows on your blog page?

<?php
if ( have_posts() ):
    while( have_posts() ): the_post(); 
?>
<h3><?php the_title(); ?></h3> 
<p><?php the_content(); ?></p>
if ( is_home() ) :?>
    <small>This entry was posted on: <?php the_date('l, jS F Y'); ?> at <?php the_time('g:i a'); ?> and is filed under <?php the_category(); ?></small>
<?php 
endif;
        endwhile;
    endif;
?>
2
  • Thanks for your input rudtek. Whilst your coding brought up a few errors, it pointed me in the right direction. I have placed my coding in the answers, should you want to refer to it in case you had errors yourself.
    – Craig
    Commented Mar 3, 2017 at 4:15
  • No problem. Glad to help. Would love the credit for answer if you don't mind.
    – rudtek
    Commented Mar 3, 2017 at 4:19
0

I have managed to resolve the issue. The code I used, should anyone find themselves in a similar situation, is as follows:

<?php if( is_home() ): ?>   
<h1>Blog Page</h1>
<?php endif; ?>

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

    <?php if( is_home() ): ?>   
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> 
    <?php the_content();?>
    <small>This entry was posted on: <?php the_date('l, jS F Y'); ?> at <?php the_time('g:i a'); ?> and is filed under <?php the_category(); ?></small>;

    <?php else: ?>
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> 

    <?php endif; ?>

<?php endwhile; ?>
<?php endif; ?>

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.