SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 30 of 30
  1. #26
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Do you know how "if", as you're already using, works? I'd rather you try to learn the PHP a little than just give you code to blindly copy and paste

    Use your in_category conditional to set a variable to a value, and then later in your code where you want to actually show something based on it, use an "if" conditional to check if that variable is equals to the value you set it to earlier.

  2. #27
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dan,

    I agree that learning would be much better. [= thanks for taking the time to explain things.

    I dont exactly know how the if im using works but I know how to make it work in the sense that I can make it do if statements - Sorta.


    PHP Code:
    <?php if( in_category($cat) ) : ?>
    $cat = info;
    $slug = get_post_meta(get_the_ID(), "info", true);


    <?php else : ?> 
    code here 
    <?php endif; ?>

    Ok, this is what I got. Im thinking its wrong. (I dont know how to call a variable other than it starts with a $).

  3. #28
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    This is the code you said works when it's up top:

    PHP Code:
    <?php if( in_category(185) ) : ?> 

    <?php else : ?> 
    code here 
    <?php endif; ?>
    I suggested setting a variable there to use later:

    PHP Code:
    <?php if( in_category(185) ) : ?> 

    <?php else : ?> 
      <?php $somevar true?>
    <?php 
    endif; ?>
    Although going in and out of PHP mode, and using only the else clause, is clunky. Reverse the logic of the if condition and you get something simpler:

    PHP Code:
    if (!in_category(185)) {
      
    $somevar true;

    Now later in your code, after all the looping stuff that makes this not work as expected anymore, you can use that variable to know you're in the category you wanted.

    PHP Code:
    if (isset($somevar) && $somevar == true) {
      
    //code here


  4. #29
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dan,

    Once again, I am amazed with your response time.


    I see what you did up until the middle part, so I will give it a try and see how everything plays out.

    I'll let you know. [=


    Thanks again.

  5. #30
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dan,

    Sorry for the slow feedback, ive been unable to get online for a few days.

    I tried out the code and everything seems to be working. thanks!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •