WPNovice WPNovice - 1 year ago 83
PHP Question

if is home, check post type, echo if certain result? (wordpress)

Hi i'm wondering if someone could help me with the correct syntax for checking for a post type when on the index feed, currently I'm trying this -

<div class="<?php if(is_home() )
{<?php if ( 'movies' == get_post_type() ) { echo 'textbox';}?> ;}?>">

Answer Source

No need for multiple PHP open tags.

<div class="<?php if (is_home() && (get_post_type() == 'movies')) { echo 'textbox';} ?>">    </div>

What I would probably do in this situation is clear it up a bit:

$class = (is_home() && get_post_type()==='movies') ? 'textbox' : '';
echo '<div class="', $class, '"></div>';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download