1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

need some wordpress help

Discussion in 'PHP' started by ansi, Mar 11, 2008.

  1. #1
    in my theme, while outputting all posts, im trying to determine if a post belongs to a certain category or not. if so, show an icon. i can get the id of each posts's category by using

    
    $cat =  get_cat_ID( 'up, down, left, right' );
    
    PHP:
    up, down, left, right is the name of the category i want to check and see if the post is in. now the function, 'the_category()' outputs the category name. is there something that essentially the same but returns a variable instead of echoing it? im confused as heck here. and wordpress really isnt my area of expertise so any help would be appreciated.
     
    ansi, Mar 11, 2008 IP
  2. CodyRo

    CodyRo Peon

    Messages:
    365
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I don't know WordPress that well either but you can probably modify the get_cat_id() function to return the value instead of echoing it. If you can give me (us?) the code to that function that would help :).
     
    CodyRo, Mar 11, 2008 IP
    ansi likes this.
  3. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #3
    i solved it using get_the_category().
    here's the code i used to set a classname based on what category the post is in so if anyone else is wandering how to do it, here you go.

    
    		<?php
    	
    			$udlr_cat =  get_cat_ID( 'up, down, left, right' );
    			$ff_cat = get_cat_ID( 'flammable firewall' );
    
    			$cats = get_the_category();
    			foreach($cats as $cat)
    				$cid = $cat->cat_ID;
    
    			if ( $cid == $udlr_cat )
    				$clname = "udlr";
    			else if ( $cid == $ff_cat )
    				$clname = "ff";
    		?>
    
    PHP:
    thanks for the input though, cody. it's appreciated.
     
    ansi, Mar 12, 2008 IP