[Resolved] Add content after the first post's title in categories

Home Forums Support [Resolved] Add content after the first post's title in categories

Home Forums Support Add content after the first post's title in categories

  • This topic has 3 replies, 2 voices, and was last updated 7 years ago by Tom.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #295156
    Inverweb Spain, S.L.

    Hello,

    I would like to add content only after the first post’s title in categories, so I have the following code:

    GP Hook: After Entry Title

    <?php
    if(is_category() /*&& post_index_within_loop == 0 */)
    {
        echo "my content";
    }
    ?>

    But I need some function to get the post index withing the loop, is there any hook to achieve it?

    Regards

    #295301
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Not 100% sure it’s possible, but if it is, this will be how to do it:

    <?php
    global $wp_query;
    if ( 0 === $wp_query->current_post && is_category() ) {
        echo 'My content';
    }
    ?>
    #295569
    Inverweb Spain, S.L.

    Yes, it worked! Thanks

    #295825
    Tom
    Lead Developer
    Lead Developer

    You’re welcome 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.