• Resolved ggg377

    (@ggg377)


    Hi, I’m trying to figure out how to include a custom php string within WordPress’s is_home() function. The catch is I want it to be surrounded by a div.

    My current setup looks something like this:

    <?php if ( is_home() ) {
    <div class="unimportant"> if(function_exists('tptn_show_daily_pop_posts')) tptn_show_daily_pop_posts(); </div>
    }
    ?>

    but it throws a syntax error. The custom string looks this unmodified:

    <?php if(function_exists('tptn_show_daily_pop_posts')) tptn_show_daily_pop_posts(); ?>.

    It should look something like this: if is_home: div—tptn_show_daily_pop_posts—/div. The solution should be a rather quick one, but I’m having issues with syntax.

    Thanks in advance for your replies.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Try this…

    <?php 
    
    if ( is_home() ) {
        ?><div class="unimportant"><?php
            if(function_exists('tptn_show_daily_pop_posts'))
                tptn_show_daily_pop_posts();
        ?></div><?php
    }
    
    ?>

    It’s untested.. but assuming your functions are correct… it should work.

    Thread Starter ggg377

    (@ggg377)

    Hey Josh, thanks for answering.

    For some reason the is_home functionality doesn’t work. The tptn_show_daily_pop_posts function shows up on all pages.

    Try using “is_front_page” instead of “is_home”.

    Here is a list of all WP conditionals:
    http://codex.wordpress.org/Conditional_Tags

    Thread Starter ggg377

    (@ggg377)

    It still doesn’t work. I’m pretty sure I’m not mixing something up. A previous similar is_home function I had in place of this worked.

    Okay, so let’s try..

    if ( is_home() ) {
        echo 'Testing...';
    }

    Does that work correctly?

    Thread Starter ggg377

    (@ggg377)

    Ah I’m sorry Josh. It was my mistake. I forgot to put another part of a code I didn’t post about here within the tags so I was surprised when it showed up everywhere. I got it now.

    Thanks a lot for your time 🙂

    Excellent 🙂

    My pleasure! Very glad you got it working!!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Php if within if problem (is_home function)’ is closed to new replies.