Need working fix to IF statement.

Discussion in 'WordPress' started by goneinsane, Feb 10, 2011.

  1. #1
    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>&nbsp;&nbsp;<?php endif; ?>
                                  <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&amp;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(); ?>&amp;action=setSold"><?php _e('Mark as Sold', 'appthemes'); ?></a>
                                 <?php else : ?>
    							 <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&amp;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(); ?>&amp;action=setRented"><?php _e('Mark as Rented', 'appthemes'); ?></a>
                                 <?php else : ?>
    							 <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&amp;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(); ?>&amp;action=setFound"><?php _e('Mark as Found', 'appthemes'); ?></a>
                                 <?php else : ?>
    							 <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&amp;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):

     
    goneinsane, Feb 10, 2011 IP
  2. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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(); ?>&amp;action=setSold"><?php _e('Mark as Sold', 'appthemes'); ?></a>
    	<?php else : ?>
    	<a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&amp;action=unsetSold"><?php _e('Unmark as Sold', 'appthemes'); ?></a>
    	<?php endif; ?>
    <?php endif; ?>
    
    Code (markup):
     
    Cash Nebula, Feb 11, 2011 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,846
    Likes Received:
    4,542
    Best Answers:
    123
    Trophy Points:
    665
    #3
    sarahk, Feb 14, 2011 IP
  4. goneinsane

    goneinsane Well-Known Member

    Messages:
    303
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    130
    #4
    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):
     
    goneinsane, Feb 14, 2011 IP
  5. sarahk

    sarahk iTamer Staff

    Messages:
    28,846
    Likes Received:
    4,542
    Best Answers:
    123
    Trophy Points:
    665
    #5
    You can leave out the second "if" before the brackets
     
    sarahk, Feb 15, 2011 IP
  6. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #6
    :confused: 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>&nbsp;&nbsp;<?php endif; ?>
    <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&amp;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(); ?>&amp;action=setSold"><?php _e('Mark as Sold', 'appthemes'); ?></a>
    <?php else : ?>
    <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&amp;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(); ?>&amp;action=setRented"><?php _e('Mark as Rented', 'appthemes'); ?></a>
    <?php else : ?>
    <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&amp;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(); ?>&amp;action=setFound"><?php _e('Mark as Found', 'appthemes'); ?></a>
    <?php else : ?>
    <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&amp;action=unsetFound"><?php _e('Unmark as Found', 'appthemes'); ?></a>
    <?php endif; ?>
    <?php } ?>
    
    Code (markup):
     
    Cash Nebula, Feb 15, 2011 IP
  7. goneinsane

    goneinsane Well-Known Member

    Messages:
    303
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    130
    #7
    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.
     
    goneinsane, Feb 19, 2011 IP
  8. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #8
    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>&nbsp;&nbsp;<?php endif; ?>
    <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&amp;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(); ?>&amp;action=setSold"><?php _e('Mark as Sold', 'appthemes'); ?></a>
    <?php else : ?>
    <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&amp;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(); ?>&amp;action=setRented"><?php _e('Mark as Rented', 'appthemes'); ?></a>
    <?php else : ?>
    <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&amp;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(); ?>&amp;action=setFound"><?php _e('Mark as Found', 'appthemes'); ?></a>
    <?php else : ?>
    <a href="<?php echo CP_DASHBOARD_URL; ?>?aid=<?php the_id(); ?>&amp;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.
     
    Cash Nebula, Feb 19, 2011 IP