I'm trying to allow a link to only show under a particular category which I have already created in wordpress. Where it says "Mark as Sold" and "Unmark as sold" should only show up if it's in category id 17. I need to change the "if" statement to include this as well as these current perimeters. Anyone know what I can do here. Code is below. } else { ?> <?php if(get_option('cp_ad_edit') == 'yes'): ?><a href="<?php echo CP_EDIT_URL; ?>?aid=<?php the_id(); ?>"><img src="<?php bloginfo('template_directory'); ?>/images/pencil.png" title="" alt="" border="0" /></a> <?php endif; ?> <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=<?php echo $postaction; ?>"><img src="<?php bloginfo('template_directory'); ?>/images/<?php echo $postimage; ?>" title="" alt="" border="0" /></a><br /> <?php if(get_post_meta(get_the_id(), 'cp_ad_sold', true) != 'yes' ) : ?> <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=setSold"><?php _e('Mark as Sold', 'appthemes'); ?></a> <?php else : ?> <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=unsetSold"><?php _e('Unmark as Sold', 'appthemes'); ?></a> <?php endif; ?> <?php if(get_post_meta(get_the_id(), 'cp_ad_rented', true) != 'yes' ) : ?> <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=setRented"><?php _e('Mark as Rented', 'appthemes'); ?></a> <?php else : ?> <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=unsetRented"><?php _e('Unmark as Rented', 'appthemes'); ?></a> <?php endif; ?> <?php if(get_post_meta(get_the_id(), 'cp_ad_sold', true) != 'yes' ) : ?> <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=setFound"><?php _e('Mark as Found', 'appthemes'); ?></a> <?php else : ?> <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=unsetFound"><?php _e('Unmark as Found', 'appthemes'); ?></a> <?php endif; ?> <?php } ?> Code (markup): I'm pretty sure this is the line that the change has to happen. Thanks. if(get_post_meta(get_the_id(), 'cp_ad_sold', true) != 'yes' ) : Code (markup):
Try this: <?php if(is_category('17')) : ?> <?php if(get_post_meta(get_the_id(), 'cp_ad_sold', true) != 'yes' ) : ?> <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=setSold"><?php _e('Mark as Sold', 'appthemes'); ?></a> <?php else : ?> <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=unsetSold"><?php _e('Unmark as Sold', 'appthemes'); ?></a> <?php endif; ?> <?php endif; ?> Code (markup):
Better still look at the option to give a category its own template and I'm sure you'll find other tweaks you would want to make. Much simpler than loading in a stack of ifs about the place. http://codex.wordpress.org/Category_Templates In what way has Cash Nebula's code not worked though? ref: http://codex.wordpress.org/Function_Reference/is_category
There is lots missing in his replacement of the code. I could tell by looking at it that there were going to be some important details left out. Some how I have to get the second if in this line. if(get_post_meta(get_the_id(), 'cp_ad_sold', true) != 'yes' ) : Code (markup): Something that says "if this and that". Here's my guess at it, but of course it doesn't work or I wouldn't be posting here. if(get_post_meta(get_the_id(), 'cp_ad_sold', true) != 'yes' && if(is_category('17'))) : Code (markup):
Maybe I should have said that it was a partial replacement for just five lines, not the entire code. This is the whole thing: } else { ?> <?php if(get_option('cp_ad_edit') == 'yes'): ?><a href="<?php echo CP_EDIT_URL; ?>?aid=<?php the_id(); ?>"><img src="<?php bloginfo('template_directory'); ?>/images/pencil.png" title="" alt="" border="0" /></a> <?php endif; ?> <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=<?php echo $postaction; ?>"><img src="<?php bloginfo('template_directory'); ?>/images/<?php echo $postimage; ?>" title="" alt="" border="0" /></a><br /> [COLOR="red"]<?php if(is_category('17')) : ?> <?php if(get_post_meta(get_the_id(), 'cp_ad_sold', true) != 'yes' ) : ?> <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=setSold"><?php _e('Mark as Sold', 'appthemes'); ?></a> <?php else : ?> <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=unsetSold"><?php _e('Unmark as Sold', 'appthemes'); ?></a> <?php endif; ?> <?php endif; ?>[/COLOR] <?php if(get_post_meta(get_the_id(), 'cp_ad_rented', true) != 'yes' ) : ?> <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=setRented"><?php _e('Mark as Rented', 'appthemes'); ?></a> <?php else : ?> <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=unsetRented"><?php _e('Unmark as Rented', 'appthemes'); ?></a> <?php endif; ?> <?php if(get_post_meta(get_the_id(), 'cp_ad_sold', true) != 'yes' ) : ?> <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=setFound"><?php _e('Mark as Found', 'appthemes'); ?></a> <?php else : ?> <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=unsetFound"><?php _e('Unmark as Found', 'appthemes'); ?></a> <?php endif; ?> <?php } ?> Code (markup):
Is this going to be the same if it's a child category. For some reason it's not work and I'm wondering if it has something to do with being a child category.
Ah sorry, I made a typo. Use this line instead: <?php if(in_category('17')) : ?> } else { ?> <?php if(get_option('cp_ad_edit') == 'yes'): ?><a href="<?php echo CP_EDIT_URL; ?>?aid=<?php the_id(); ?>"><img src="<?php bloginfo('template_directory'); ?>/images/pencil.png" title="" alt="" border="0" /></a> <?php endif; ?> <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=<?php echo $postaction; ?>"><img src="<?php bloginfo('template_directory'); ?>/images/<?php echo $postimage; ?>" title="" alt="" border="0" /></a><br /> [COLOR="blue"]<?php if(in_category('17')) : ?>[/COLOR] <?php if(get_post_meta(get_the_id(), 'cp_ad_sold', true) != 'yes' ) : ?> <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=setSold"><?php _e('Mark as Sold', 'appthemes'); ?></a> <?php else : ?> <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=unsetSold"><?php _e('Unmark as Sold', 'appthemes'); ?></a> <?php endif; ?> <?php endif; ?> <?php if(get_post_meta(get_the_id(), 'cp_ad_rented', true) != 'yes' ) : ?> <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=setRented"><?php _e('Mark as Rented', 'appthemes'); ?></a> <?php else : ?> <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=unsetRented"><?php _e('Unmark as Rented', 'appthemes'); ?></a> <?php endif; ?> <?php if(get_post_meta(get_the_id(), 'cp_ad_sold', true) != 'yes' ) : ?> <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=setFound"><?php _e('Mark as Found', 'appthemes'); ?></a> <?php else : ?> <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&action=unsetFound"><?php _e('Unmark as Found', 'appthemes'); ?></a> <?php endif; ?> <?php } ?> Code (markup): BTW, you are right about child categories. The in_category() function does not work for them, only the parent category. But it should work now so long as your child category is 17.