I am trying to execute a hook in a specific category, and it is not working. The theme I'm using has easy hooks, and I'm trying to put it before the content on a specific category page. I'm inserting the following at the moment just as a test, but I have a basic html table that is going in there. What code do I need to be putting in here differently?
<?php if (in_category('3'){?>
<a href="http://wpquestions.com"> TESTING TESTING TESTING </a>
<?php }?>
Pippin Williamson answers:
Use this:
<?php if ( is_category('3') || in_category('3')) { ?>
<!--stuff here-->
<?php } ?>
Utkarsh Kukreti answers:
For 'category' archive page, use is_category.
Edit: Is it a post in a specific category, or the category archives page?
Ashley comments:
I need it to show up on both, really.
Peter Michael answers:
Try if (is_category('my-category-slug'))
Ashley comments:
I tried the slug, but it still doesn't work..
Rashad Aliyev answers:
Hi you should specify categories by name. For example
<?php
if ( in_category('fruit') ) {
include 'single-fruit.php';
} elseif ( in_category('vegetables') ) {
include 'single-vegetables.php';
} else {
// Continue with normal Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
// ...
}
?>
Ashley comments:
I have the original permalinks enabled though- so doesn't it need to be the number?
Ashley comments:
I tried the slug and it still doesn't work..
Rashad Aliyev comments:
Please send your all of code to me for analyzing.
Rashad Aliyev comments:
Define your permalinks before and then use the slug! If you still can't make it, I'm available.