Forums

[resolved] Page Template or Conditional Tag? (6 posts)

  1. jennsweb
    Member
    Posted 3 years ago #

    I have been looking around for the best solution to a design challenge. The client would like to have one main url and several mini-sites off of that url all using the same style sheet. I thought this could be done most efficiently with page templates and then each template would include different header, sidebar and footer files. However, could this be done with simply the page.php file and conditional tags? Or, am I overthinking and do I simply need to include the conditional tags in my page templates?

  2. stvwlf
    Member
    Posted 3 years ago #

    Hi

    You can do it either way. If you are comfortable with code, doing it in code works just fine. If you are more comfortable with custom page templates, that works well also. You can even combine the two for places where it makes sense to use a custom template, and can have conditional code in it also.

  3. jennsweb
    Member
    Posted 3 years ago #

    Thanks stvwlf!
    That was my gut feeling too. I need to display different content in each template's header, sidebar and footer and it seems like there was a different coding method being used each time I tried finding a solution! Basically what I want to happen is that when I assign a template to a particular page, when that page is displayed, it includes the correct header, sidebar and footer for that page template.

  4. jennsweb
    Member
    Posted 3 years ago #

    I have been trying to do this the way it says to in the WP codex (both methods) but when I set the page's template to lfcl.php (name of the template) and tell it to display header-lfcl.php, sidebar-lfcl.php and footer-lfcl.php using either php includes or get_header ('lfcl') methods (both seen in the codex), I get a blank screen when I go to that page. This seems like a fairly straightfoward process, create template, create header, sidebar and footer for that template, and then call those from the template page.

    I am creating this on a subdomain testsite (testblog2.jennmearswebdesign.com) so could that be what's going on? Should I be using Permalinks? Each of those sections needs to include slightly different content.

  5. stvwlf
    Member
    Posted 3 years ago #

    when I set the page's template to lfcl.php (name of the template)

    if lfcl.php is the name of the template file, that is not correct. Each custom template php file needs a header at the top

    <?php
    /*
    Template Name: Snarfer
    */
    ?>

    In that example, within the WP page editor you would set the Template pulldown to Snarfer. Unless you used "Template Name: lfcl.php", you would not set the template to lfcl.php but the Template Name you assigned within the php file I'd suggest not using using a Template Name that ends in .php - "lfcl" would be fine.

    You can not pass a parameter within get_header()
    Don't use get_header()
    use <?php include( TEMPLATEPATH . '/header-lfcl.php' ); ?>

    TEMPLATEPATH points to the server location of the theme folder.

    Use the same syntax for sidebar and footer.
    <?php include( TEMPLATEPATH . '/sidebar-lfcl.php' ); ?>
    <?php include( TEMPLATEPATH . '/footer-lfcl.php' ); ?>

    Permalinks is another issue, unrelated to this one.
    As long as you created the WP install at testblog2.jennmearswebdesign.com with that as the site URL, it should work fine. If you initially created it at a different URL and moved it to the subdomain you will have to clean up references in the database to the original URL.

  6. jennsweb
    Member
    Posted 3 years ago #

    Eureka!

    The issue was 2 things:

    I had originally created the template file by pasting code into and renaming the index.php file. I should have used the page.php as a starting point. (actually did use the right naming convention as well)

    Then, I had some nesting issues. The footer-lfcl.php file also included the call for the sidebar-lfcl.php file and using the template tag for that seemed to throw things off. I snipped the div that contained the sidebar-lfcl include and simply pasted it before the footer-lfcl.php include tag in the lfcl.php file.

    Now the page at least displays all the content.

    Thanks Stvwlf!

Topic Closed

This topic has been closed to new replies.

About this Topic