Responsive WordPress Theme – Caliber

A theme with simple controls and limitless potential. Work fast and build an amazing website!   Find out more »

UpThemes – Beautiful WordPress Themes

Create a site your church, gallery, newspaper, blog, recipes, band and more!   See the themes »

Need a little help?  Find answers quickly by searching the forum.
Group Admins
  • andy
  • jeffw

Support for: Salutation: WordPress + BuddyPress Theme

Salutation (WordPress)

Public Group  |  active 4 years, 4 months ago ago
Viewing post 1 to 15 (26 total posts)

(solved) Default Layout for Custom Post Types

  • elunder

    said

    One problem emerged for my site. Is there a possibility to set the default layout for custom post types? They are not listed in Appearance->Layouts.

    If you can write a code block that I can stick into my theme admin files, that would be great. (And id would probably be a good feature for the theme as well…)

    Thanks in advance,
    elunder

  • andy

    said

    This is also on my wish list. I want to include features in my framework to recognize custom post types automatically and provide layout options. As of now you must add the code for the new layouts manually, but it’s not difficult. Besides just recognizing the post types, I also hope to build out a way that the function which is called to set the page “context” to determine the theme’s template-[context].php file can have an additional parameter which will generate a custom layout field in the admin as well.

    I don’t know how far out these features are because right now I’m spending most of my time focusing on the actual theme code and cannot dedicate much to the underlying framework. I do try to make small updates for the areas I’m working on as I do theme updates but these are minimal.

    As for creating the fields manually. There are a couple of changes you must make, below are the steps. You may not need to do step 1 and 2 if you already have a file with the required theme layout function and template file.

     

    1. Open the file archive-[post-type].php or whatever the name is of your custom post type target page. Copy the content out of the file and save it to a new file named “template-[context].php” where the “[context]” is the description of the output type. If you are going to use an existing templage file like “template-blog.php” or “template-page.php” you do not need to create the new file.

     

    2. Copy the default layout function to your archive-[post-type].php file and update the function parameter for “context” to be the same as the file template-[context].php.

    create_page_layout('context');

     

    3. Open the file “framework/layout-settings/admin-options-defaults.php” and duplicate the code for the default “Page” layout. You’ll find it around line 100. It will look like this:

    // Pages
    $select = $select_layout;
    $comment = __('The default layout to use for new pages.', THEME_NAME);
    $comment = $layout_admin->format_comment($comment);
    $row = array(__('Pages', THEME_NAME), $layout_admin->settings_select('layout,page', $select) . $comment);
    $layout_admin->setting_row($row);

     

    4. Change the reference for the context (the 5th line in the block of code you just duplicated). I’ve demonstrated the change to that line in the code below.

    $row = array(__('Post-type Name', THEME_NAME), $layout_admin->settings_select('layout,context', $select) . $comment);

    The “context” must be exactly the same as what you entered for the function in step 2.

     

    5. Open the file “framework/layout-settings/settings-object.php” and add the new context to the array on line 25 (or near there) :

    'layout' => array('header', 'footer', 'default', 'home', 'page', 'post', 'blog', 'category', 'author', 'tag', 'date', 'search', 'error', '[context]' )

    (The example above is shortened from the actual code in the file to make it easier to read. Just add your context to the end of the array, the order of the items makes no difference.)

    That should do it. Save the files, upload them to your site.

  • elunder

    said

    I’m having trouble getting this to work. I didn’t use templates for my CPTs yet. I just didn’t need them. If I omit step 1 and 2 the layout is not applied to the custom posts if set in Appearance->Layouts.
    Edit: Does this work retroactive?

  • elunder

    said

    Fixed it. It seems as if this only works if you are using a custom template file.

  • pixelemotion

    said

    Hello,

    Some of my questions might probably be stupid but I would need some help concerning CPT

    In your step 1 >> I don’t even have an “archive-[post-type].php” even though my CPT is created and can view it (individually posts only though) – How can I generate this file in the first place ?

    When you talk about the “Context”, does it mean I can choose a name related to my CPT – ex : template-serie.php ?

    In your step 2 >> If I understand well my archive-[post-type].php should look like this ?

    I think the next steps won’t be a problem, but I guess my problem is in the first place, being able to have the code of my archive-[post-type].php (that I can’t find right now)

    Thanks a lot for your help ! (and sorry for having all these questions :) )

  • pixelemotion

    said

    I think I finally succeed to follow the steps.

    I created a new Template type called “Series”, and I can select a layout for this template.

    But How can this template will loop the custom posts I have ?

    I think I miss one step beetween having the template, and displaying the custom posts in it….

    thanks !

  • pixelemotion

    said

    Last comment before a reply (hopefully)

    My archive-series.php looks like this :

    <?php global $designBypassContent;
     
    $designBypassContent = ob_get_clean();
    create_page_layout('series');  // context = page
     
    ?>

    My template-series.php is absolutely the same as template-blog.php except I have changed the first lines :

    <?php 
      if (!$blog_query) $blog_query = $wp_query;
      $blogOptions = ($shortcode_values) ? $shortcode_values : $theLayout['series'];

    But I’m pretty sure something’s wrong cause no matter what I change in this file, it won’t have any effect on the display page…

  • andy

    said

    @pixelemotion

    Your “archive-series.php” file shouldn’t have that code. In the code I posted above it shows you should have:

    create_page_layout('series');

    That’s all it needs.

    I think it will help you a lot to read up on custom post types so you understand what these files “archive-{post-type}.php“, “single-{post-type}.php“, “page-{post-type}.php“, “taxonomy-{post-type}.php“, etc. do and then you’ll have a better grasp of what you need.

    http://codex.wordpress.org/Post_Types#Template_Files

  • andy

    said

    As some additional information. In version 1.3 of Salutation we have added the following new feature. You can specify a layout for your custom post types using a second parameter in the “create_page_layout” function.

    You can specify the layout in the function as shown below:

    create_page_layout($context, $layout_key);

    As an example usage:

    create_page_layout('blog', 'full-width');

    The first parameter is the “context” which selects the template file and the second (optional) parameter is the “layout key“. In this example the theme would load the file “template-blog.php” and display the page using the “Full Width Layout“. Depending on your install and setup the “layout key” for your full width layout may be different.

    The layout key is the value you enter field “Layout key (unique identifier)” when creating a layout (Appearance > Layouts). You can look the value up by editing any layout and copying the the key entered for the layout you want.

  • andreipop

    said

    I’m using wp-ecommerce custom post types, and I need different posts within the CPT to have different layouts (specifically different sidebars). These CPT lack template-[context] files but pull from wpsc-single_product.php

    Not sure exactly how to add the ability to each individual post within the CPT to have the layout options.

  • andy

    said

    It’s the same logic as any theme file, update the default file to have a call to create_page_layout('filename', 'full-width'); and create a new template file template-filename.php and copy the original file’s code there.

  • andreipop

    said

    Both posts pull from the same template, wpsc-single_product.php – I need to add the ability to change layouts for individual posts not the whole template. Will this add the ability to pick a layout to use for each individual post? Thanks!

  • Arrangements

    said

    I did all the steps and I am wondering how i can get my anime pages to adjust to the new changes.

    here is my set up:
    admin-options-defaults.php

        // Anime pages
        $select = $select_layout;
        $comment = __('The default layout to use for new anime pages.', THEME_NAME);
        $comment = $layout_admin->format_comment($comment);
        $row = array(__('Anime', THEME_NAME), $layout_admin->settings_select('layout,anime', $select) . $comment);
        $layout_admin->setting_row($row);

    settings-object.php

    'array' => array(
              'layout' => array('header', 'footer', 'default', 'home', 'page', 'post', 'blog', 'category', 'author', 'tag', 'date', 'search', 'error', 'bp', 'bp-activity', 'bp-blogs', 'bp-forums', 'bp-groups', 'bp-groups-single', 'bp-groups-single-plugins', 'bp-members', 'bp-members-single', 'bp-members-single-plugins', 'bbpress', 'anime' )

    template-anime.php
    test

    anime.php

    if (__FILE__ == $_SERVER['SCRIPT_FILENAME']) { die(); }
     
    /*
    * NOTE: this file is for compatibility.
    * Layouts are created in the theme options and "design-{name}.php" files.
    * Content is generated by the "template-{context}.php" files.
    */
     
    create_page_layout('anime');  // context = page

  • andy

    said

    Unfortunately troubleshooting everyone’s individual situation is not possible. There are a number of posts here on the forum that address these custom templates and post types and they detail several different methods. You should be able to accomplish what you need from the information available here on the forum.

Viewing post 1 to 15 (26 total posts)