wordpress custom pre-fixed templates

I want to create a page template that has a pre-fixed css. Lets say I name it page-sevencol.php then I know that the content will have a fixed width and a specific style and so on. My pages have different layouts thats why I need to create these kind of templates.

Is it possible? if so how? Ive looked in the wp codex and it does not seem to have the answer. Please take a minute to help me.

Read More

Thank you!

Related posts

Leave a Reply

2 comments

  1. you seem to need just a limited set of templates. The question is: do you want to apply them automatically? Basically, there are two techniques to apply a template to a page (or post or custom post, etc.) in WordPress.
    First method: using the template naming convention to get the template automatically applied to a page (or post) with the same name.
    In this case, you create a page page-mynewpage.php and this template will automatically get applied to your page named /mynewpage/.
    Second method: you create a template by creating a page (let’s say : template1.php) and declaring it as a template with a comment at the top of the page:

    /**
     * Template Name: Template1
    *
    */
    

    This template will now be selectable inside the admin of WordPress to be applied to any page:

    The Template dropdown in WordPress Admin

    So if A) you only need a limited set of templates & B) are ok to select them on a per-page basis in the admin, this is your solution. You would just need to create as many pages as you need templates, not forgetting to include the comments that declare them as templates and using a different name each time.

    If you need your templates to be applied dynamically, then we need more info about the logic to use for select each template…

    EDIT : That is it, Abel (just read your comment). Your page is mainly generated with 4 elements: header.php, sidebar.php, footer.php and another page to produce the content, but this page is different depending on where you are in the site. If you are on a page, it will be, by default, page.php. If you are reading a post, WordPress will by default use single.php.

    To apply all your different templates, just go and open page.php in your theme folder. Save it under another name, like page-template7cols.php. Insert a comment like I just explained above, so this template will show in your admin next time you create a new page. Adapt it the way you want (changing the HTML / PHP and therefore adapting the way the content of the page will be displayed). Do the same for your other 9 templates.

    Then, everytime you create a new page, just start by selecting the proper template in your dropdown (see previous screen capture). And whenever you will make a change to page-template7cols.php, for example, the changes will be reflected on all pages for which you have selected this template.

  2. /**
      Template Name: Template1
     */
      <?php get_header(); ?>
       <div class="content-wrap sevencol clearfix">
    <div class="row clearfix">
    
        <div class="content">
            <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
             <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    
                  <?php the_content(); ?>
    
                   <?php endwhile; endif; ?>
                         </div>
        <?php get_sidebar(); ?>
          <?php get_footer(); ?>