0

I am editing an older wordpress theme, and I am receiving this error: Fatal error: Call to undefined function is_even().

    <?php if($blog_post_query->have_posts()): ?>
    <ul>
        <?php
        $blog_count = 0;
        while($blog_post_query->have_posts()): $blog_post_query->the_post(); $blog_count++;//<!-- error line -->
            $style = ( is_even( $blog_count ) ) ? 'even' : 'odd';?>
            <li class="<?php echo $style; ?>">
                <h2><?php te_title(); ?></h2>
                <?php the_content(); ?>
            </li>
        <?php endwhile; ?>
        <?php else: ?>
            <?php get_template_part( 'template-content/content', 'none' ); ?>
        <?php endif; ?>
    </ul>
    <div class="row">
        <a href="<?php echo esc_url( home_url( '/' ) ); ?>fit-news" class="button button-blue pull-right">Read More</a>
    </div>
</div>
1

That's because the is_even function isn't defined. You can either make sure it's defined in the themes function or replace it:

To replace it, you can use

$style = ( $blog_count % 2 ) ? 'even' : 'odd';

or define the is_even funtion

function is_even( $blog_count ) {
    if ( $blog_count % 2 )
        return true;
    return false;
}
  • My friend, I think the only reason this hasn't been accepted is you haven't used scope {} after if ( $blog_count % 2 ), else is perfect. – prosti Jan 18 '17 at 13:19
  • This should work without the brace, you can test it yourself. Thanks for the heads up though. – Tunji Jan 18 '17 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.