• Resolved andrew-s3

    (@andrew-s3)


    I’m trying to create some conditional content in my index.php file for my theme that will display a DIV I’ve created but only on the home page. I’ve used WidgetLogic before to create Conditional Sidebar Widgets, but I’m unsure how to write this PHP code w/in my Theme files. Can someone please provide me with the proper code to display this div — pastebin

    I’m placing this above where “the-feed” will pull the TITLE information. I’m sure it only requires an is_home() statement; but i’m unsure of the PHP call to make this all happen.

    Thanks in advance to any/all who help ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter andrew-s3

    (@andrew-s3)

    Any and all suggestions or insight would be appreciated ?? thx

    You should read up on conditional statements in your functions.php:

    function homepageimage() {
    //then define the action to take:
    if (is_home()) {?>
    //Div goes here
    
    <?php }
    //end action:
    }
    //now we can add our new action to the appropriate place like so:
    add_action('thematic_belowheader', 'homepageimage');

    This is the code I used to place an image above my header… It uses action hooks, in my thematic theme.

    So find your action hook, and use the conditional statement to make it appear…

    Hope this helps.

    Thread Starter andrew-s3

    (@andrew-s3)

    So I would define the function homepageimage() in my functions.php and use my conditional statement is_home() and then would use the add_action(‘homepageimage’); to place it into my theme where I need it?

    Read this , it may help you .
    Assign the div-code to a variable : $val = “bla-bla -bla div div div” ;
    Now into the conditional tag : echo $val ;

    You need to find the action hook / create on in your functions.php for your theme…

    What theme are you using?

    Thread Starter andrew-s3

    (@andrew-s3)

    I’m creating my own bigdanprice; my functions.php only calls for my custom menus… that’s it. So i’m completely lost when you say “find the action hook”.

    Kostas, I’m familiar with that page of www.ads-software.com; I’m just not familiar with the implementation.

    Have you considered using something like Thematic as a basis and using a child theme…
    Makes using things like conditional content, extremely easy… I would recommend it.
    (Its free as well!)

    Thread Starter andrew-s3

    (@andrew-s3)

    Personally I’d rather keep it as custom as possible; hence why I’m going this route. My company prides itself on its custom work.

    I guess I’ll just wing it and see what I come up with.

    Thread Starter andrew-s3

    (@andrew-s3)

    and this

    <?php if ( ! is_home() ) {?>
    
     Insert your markup ...
    
    <?php }?>

    Worked ??

    I just changed the is_home() to is_page(‘#’) and removed the ! and it worked like a charm. Thanks for all the help and insight guys.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Creating Conditional Content on my home page’ is closed to new replies.