• hello,

    I’m trying to link certain files in the header in certain situations. Basically when your viewing the static front page of my site one file will be included in the header, where in everyother situation a second file will be included instead. I understand the concept of how this will work, but the syntax is alittle iffy for me.. so the pseudo code would look like..

    if ($frontpage == 1) {
    include(‘front-page.php’);
    }
    else {
    include(‘not-front.php’);
    }

    please help me with the syntax, thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Try with this:

    <?php if (is_front_page()) {
       include ('front-page.php');
    } else {
       include ('not-front.php');
    } ?>
    Thread Starter bluedrag

    (@bluedrag)

    it still doesn’t seem to be working. Here is the exact code I am using, perhaps I’m using the TEMPLATE_PATH tag wrong.. Thanks for your help.

    <?php
    
        if (is_front_page()) {
           include ('TEMPLATE_PATH. ../westbury/front-contentheader.php');
        }
    
        else {
           include ('TEMPLATE_PATH. contentheader.php');
        }
    
        ?>

    The TEMPLATE_PATH is wrong, must be:

    <?php if (is_front_page()) {
    	include (TEMPLATEPATH . '/westbury/front-contentheader.php');
    } else {
    	include (TEMPLATEPATH . '/contentheader.php');
    } ?>
    Thread Starter bluedrag

    (@bluedrag)

    Ok so I got the header working using the bloginfo(‘template_url’) tag instead of the TEMPLATEPATH tag. Now I am trying to do the same in the footer but it doesn’t seem to be working. Not only do I loose my footer when I impliment this code but the WP admin bar disapears

    <?php
        if (is_front_page()) {
                include (bloginfo("template_url") . 'front-contentfooter.php');
        }
    
        else {
                include (bloginfo("template_url") . 'contentfooter.php');
        }
        ?>
    
        <?php
    
        <!--basic2col_contentfooter();-->
        wp_footer();
    
        ?>
    
        <?php /*Basic2Col WordPress theme by Kristin K. Wangen https://wangenweb.com/ */ ?>
    
        </body>
        </html>

    any help is appreciated

    You have not said what is in the two files, but if it is just a different footer content then look at template parts.

    Rename the files and move them both to the theme or child themes folder, footer-content.php and footer-front.php

    Then the code is as easy as:

    <?php if ( is_home() || is_front_page() ) : ?>
        <?php get_template_part('footer','front'); ?>
    <?php else : ?>
        <?php get_template_part('footer','content'); ?>
    <?php endif; ?>

    Even easier, just take the code above and save this in a third file called footer-custom.php

    Then just call this in each file where required with a single line:

    <?php get_template_part('footer','custom'); ?>

    BTW you are missing the folder switch / :
    include ( bloginfo("template_url") .'/front-contentfooter.php' );

    HTH

    David

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘includes and wordpress’ is closed to new replies.