0

I am trying to add some text to the end of every post belonging to a specific category. I am using the following code -

<div class="repair-tool">
    <?php 
    $catarray = get_the_category( $post->ID );
    foreach ($catarray as $cat) {
        $catid = $cat->term_id;
    
        if ($catid == 1234) {
          echo 'text';
        }
    
    } ?>
</div>

This is working successfully but div class I am using is being shown in every post of the website instead. Please somebody help me out.

1 Answer 1

2

It seems you are pointing to this div class "repair-tool". Correct?

If yes then you can modify your code like the below:

<?php
if( in_category( 1234, $post->ID ) ){
    echo '<div class="repair-tool">text</div>';
}
?>
1
  • Thank you so very much, Tiwari ji. Worked like a charm.
    – SK21
    Commented Nov 9, 2022 at 17:53

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.