Forums

[resolved] Creating Conditional Content on my home page (10 posts)

  1. andrew-s3
    Member
    Posted 9 months ago #

    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 :)

  2. andrew-s3
    Member
    Posted 9 months ago #

    Any and all suggestions or insight would be appreciated :) thx

  3. bigdanprice
    Member
    Posted 9 months ago #

    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.

  4. andrew-s3
    Member
    Posted 9 months ago #

    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?

  5. kostas123
    Member
    Posted 9 months ago #

    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 ;

  6. bigdanprice
    Member
    Posted 9 months ago #

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

    What theme are you using?

  7. andrew-s3
    Member
    Posted 9 months ago #

    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 wordpress.org; I'm just not familiar with the implementation.

  8. bigdanprice
    Member
    Posted 9 months ago #

    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!)

  9. andrew-s3
    Member
    Posted 9 months ago #

    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.

  10. andrew-s3
    Member
    Posted 9 months ago #

    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.

Reply

You must log in to post.

About this Topic