WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] if is home includes not working 2.8.6? (13 posts)

  1. Mobster
    Member
    Posted 4 years ago #

    What could be causing this to not work in 2.8.6?

    <?php if ( is_home() ) { include ('mypage.php'); } ?>

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    Try:

    <?php if ( is_home() ) { include (TEMPLATEPATH . 'mypage.php'); } ?>

    I'm assuming that mypage.php is in your current theme folder, yes?

  3. Mobster
    Member
    Posted 4 years ago #

    Yes it is. That's not working either?

  4. esmi
    Forum Moderator
    Posted 4 years ago #

    Plan B:

    <?php if ( is_home() || is_front_page() ) { include (TEMPLATEPATH . 'mypage.php'); } ?>

  5. Mobster
    Member
    Posted 4 years ago #

    Well... I appreciate your help but neither are doing the trick. They make sense though...

    Isn't there a stylesheet directory version of this?

  6. esmi
    Forum Moderator
    Posted 4 years ago #

    Not that I recall. TEMPLATEPATH is the correct constant - although:

    `<?php if ( is_home() ) { include (TEMPLATEPATH . '/mypage.php'); } ?>

    might work a lot better. I forgot that TEMPLATEPATH doesn't include a trailing /. >:(

  7. Mobster
    Member
    Posted 4 years ago #

    This is crazy. None of the above work. I have used just about every version include tag you mentioned for what seems like years with no issues? Could this be a bug of some sort?

  8. Mark / t31os
    Moderator
    Posted 4 years ago #

    Are you seeing an error message, "Failed to include"... etc etc..

    If you don't see an error it could be that the file is getting included but simply not producing an output..

    If no error, try changing to a require, and see if it then bombs out..

  9. Mobster
    Member
    Posted 4 years ago #

    Nope, No errors.

    This works:

    <?php include( TEMPLATEPATH . '/mypage.php' ); ?>

    This doesn't:

    <?php if ( is_home() ) { include ( TEMPLATEPATH . '/mypage.php'); } ?>

    Why not in 2.8.6? I guess that's the million dollar question considering all of the above are played out as methods to include in wordpress documentation?

    WordPress Codex

    I smell a bug...

  10. Mobster
    Member
    Posted 4 years ago #

    Ok, I think I'm on to something here.

    I ran across an include in my code I forgot about.

    Here it is:

    <?php if ( is_home() ) { include ('mypage.php'); } ?>

    It works perfectly. I experimented buy putting the same code right below it and it only included one instance.

    Has there been some sort of limit to the amount of if's or if homes allowed on one page?

    Just a guess...

  11. Mobster
    Member
    Posted 4 years ago #

    Another issue, my custom queries aren't working.

    <?php $recent = new WP_Query("cat=5&showposts=5");  ?>
                        <span>
                        <?php while ($recent->have_posts()) : $recent->the_post(); ?>
                        <a href="<?php the_permalink() ?>" title="<?php _e('Permanent link to'); ?>
    <?php the_title(); ?>">
                        <?php the_title(); ?>
                        </a>
                        <?php endwhile;?>
  12. Mark / t31os
    Moderator
    Posted 4 years ago #

    Aren't working in what way, no output, an error?.. (problem code usually at least outputs an error).

    Dump your query data onto the screen so you can make sure it exists..

    <pre><?php print_r( $recent ); ?></pre>

    ...etc...

    There's also WP_DEBUG for debugging purposes to..

    Before you go fiddling or digging in more code though, noone has brought it up... but do you have any plugins enabled, and if so, have you tested (if only for testing sake) with them disabled?
    Also tried another theme also perhaps? ... again if only for testing sake...

  13. Mobster
    Member
    Posted 4 years ago #

    Thanks t3 for taking the time to assist me.

    I went through all the normal testing I always do by disabling plugins, testing bits of code. ect...

    The next thing I always try is phpMyAdmin optimize table and repair table. This time, that did the trick.

Topic Closed

This topic has been closed to new replies.

About this Topic