WPNovice WPNovice - 27 days ago 5x
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';}?> ;}?>">


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>';