0
votes

I am developing a wordpress blog theme, which shows the posts on the homepage. I am trying to show some text ONLY on the homepage, and not on page 2,3 ,4 and so on of the blog posts. The code below shows the text on all blog pages:

<?php
    if (is_front_page()) {
    ?><p>TEST FRONT PAGE</p>
    <?php
} ?>

How do I show this ONLY on the front home page (page 1, not pages after 1)?

ANSWER FOUND IN COMMENT BELOW

1
answer found: <?php $paged = $wp_query->get( 'paged' ); if ( ! $paged || $paged < 2 ) {?> <p>test</p> <?php } ?> - JCHASE11
you can answer you own question and accept it instead of posting it as a comment :). - bingjie2680
when you find answers to your own questions, don't put them under comments, put them as an independent answer and mark it 'accepted' - Capagris

1 Answers

1
votes

Instead of declaring an additional variable and checking it you can access the global in wp_query with is_paged.

<?php if (is_home() && !is_paged()) : ?>
Your front page content.
<?php endif; ?>

Or if you have a static post as the front page with its own sub pages you can use:

<?php if (is_front_page() && !is_paged()) : ?>
Your static front page content.
<?php endif; ?>

To target just the first page of the static post.