1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Two Functions

Discussion in 'Other Languages' started by babarali124, Mar 23, 2013.

  1. babarali124

    babarali124 Regular Member

    Joined:
    Jul 9, 2010
    Messages:
    252
    Likes Received:
    23
    Hello,

    I wanted to add custom text/html (adsense) to bottom and top on custom posts in certain categories and pages of my wordpress blog . I searched google and found a solution which was not complete, some guy shared a php code and said me to paste it in functions.php which i did and it worked pretty well. But the code is for just one category i need it for different categories.

    I want the code to work with more than one category, although i searched google for the solution and tried using different things like adding && and the id of the next category but nothing worked so far.

    Here is the code

    PHP:
    add_filter('the_content''custom_category_text');

    function 
    custom_category_text($content){
    global 
    $post;
    $custom_category_text '<div class="alert alert-block">This is some text inside a DIV tag</div>';
    if(
    in_category('3')){ // change catetegory ID 3
        
    $content =  $content $custom_category_text;
    }
    return 
    $content;
    }
    Please can someone amend it and provide me with the required one. Thankyou
     
  2. BlueZero

    BlueZero Power Member

    Joined:
    Jul 6, 2011
    Messages:
    500
    Likes Received:
    257
    Occupation:
    Webdeveloper, Project Manager
    Location:
    Byte in the Net
    Home Page:
    the key is this line:

    if(in_category('3')){ // change catetegory ID 3

    so if you want to show it in category 3 and in category 4 then the code will be:

    Code:
    if(in_category('3') || in_category('4') ){ // change catetegory ID 3
    
     
    • Thanks Thanks x 1
  3. babarali124

    babarali124 Regular Member

    Joined:
    Jul 9, 2010
    Messages:
    252
    Likes Received:
    23
    Thanks alot bro !!! it worked... added reputation and thanked