How do you make a WordPress front page template in the Carrington blog theme?

I tried adding a frontpage.php file to the content directory, but that wasn’t being loaded. Now I’ve added the following snippet to assure I’m getting a context of ‘frontpage’:

add_filter('cfct_context', 'scompt_front_page_context');

function scompt_front_page_context($context) {
    if( is_front_page() )
        return 'frontpage';
    return $context;
}

That is allowing me to create a frontpage.php file in the loop directory, but I’m still unable to get it to use my file for the content.

Related posts

Leave a Reply

5 comments

  1. Not exaclty sure what you’re trying to do, but in order to use a page template in WordPress, you must have this at the top of the file:

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

    and that goes before

    <?php get_header(); ?>
    

    And in order for WordPress to use the template, you have to select it in the page editing area in admin.

    So, for a “frontpage,” use a template named home.php – with the template name as above – and select it as the template to use in the page editor.

  2. you need two pages to get this to work.

    1. page_example.php (make newfile in same directory as page.php)

    2. pages/page_example.php (copy and rename page_default.php)

    page_example.php
    must have this header only

    <?php
    /*
    Template Name: Page example
    */
    
    if (__FILE__ == $_SERVER['SCRIPT_FILENAME']) { die(); }
    if (CFCT_DEBUG) { cfct_banner(__FILE__); }
    
    cfct_page('page_example');
    
    ?>
    

    and

    pages/page_example.php is the page it calls so really all your changes need to be in here.
    ie remove the side bar, get_sidebar();

    now select this page as usual when you are creating a page.

  3. This is actually a problem in the utility.php file (in the carrington core). There is a function that tells it how to get/determine the content for any given situation. The code looks like this (around line 500):

    function swpt_choose_content_template($type = 'content') {
    $files = swpt_files(swpt_PATH.$type);
    $filename = swpt_choose_single_template($files);
    if (!$filename && swpt_context() == 'page' && file_exists(swpt_PATH.$type.'/page.php')) {
        $filename = 'page.php';
    }
    
    if (!$filename) {
        $filename = swpt_default_file($type);
    }
    return apply_filters('swpt_choose_content_template', $filename, $type);
    

    }

    You need to add another case in there to have it check for the front page content template path…this would be the code (in this example, the front page is “front-page.php”):

    //checks to see if this is the front page content - this fixes the error of the framework choosing the default content rather than the front page content
    if (!$filename && swpt_context() == 'front-page' && file_exists(swpt_PATH.$type.'/front-page.php')) {
        $filename = 'front-page.php';
    }
    

    I added that right above the default case, and it instantly solved the problem of Carrington calling the default content rather than the front page content template.