ThemeShaper Forums » Development Talk

[closed]

New Page Templates in Thematic?

(15 posts)
  • Started 3 years ago by Devin
  • Latest reply from helgatheviking
  1. I'd like to see a few page templates added to Thematic core and wanted to get feedback. To start, I'd like to add a full width template. There've been a lot of questions about it here- and the new 2010 theme includes one.

    I think the only issues would be with child themes that don't have the styles set for it- but this won't be a problem unless someone upgrades their version of thematic and then tries to set the new page template. Hopefully child theme authors can just add the additional styles (or, they've called default.css and they'll be there).

    To add it to Thematic, there would need to be a new file called template-fullwidth.php. I'd use "template" as a naming convention, so we can also add a "template-blog.php" template and/or "template-magazine.php" if we want to take it that far. The code for template-fullwidth.php would be:

    <?php
    /*
    Template Name: Full Width
    */
    
        // calling the header.php
        get_header();
    
        // action hook for placing content above #container
        thematic_abovecontainer();
    
    ?>
    
    		<div id="container">
    
    			<?php thematic_abovecontent(); ?>
    
    			<div id="content">
    
    	            <?php
    
    	            // calling the widget area 'page-top'
    	            get_sidebar('page-top');
    
    	            the_post();
    
    	            thematic_abovepost();
    
    	            ?>
    
    				<div id="post-<?php the_ID(); ?>" class="<?php thematic_post_class() ?>">
    
    	                <?php 
    
    	                // creating the post header
    	                thematic_postheader();
    
    	                ?>
    
    					<div class="entry-content">
    
    	                    <?php
    
    	                    the_content();
    
    	                    wp_link_pages("\t\t\t\t\t<div class='page-link'>".__('Pages: ', 'thematic'), "</div>\n", 'number');
    
    	                    edit_post_link(__('Edit', 'thematic'),'<span class="edit-link">','</span>') ?>
    
    					</div>
    				</div><!-- .post -->
    
    	        <?php
    
    	        thematic_belowpost();
    
    	        // calling the comments template
    	        thematic_comments_template();
    
    	        // calling the widget area 'page-bottom'
    	        get_sidebar('page-bottom');
    
    	        ?>
    
    			</div><!-- #content -->
    
    			<?php thematic_belowcontent(); ?> 
    
    		</div><!-- #container -->
    
    <?php 
    
        // action hook for placing content below #container
        thematic_belowcontainer();
    
        // calling footer.php
        get_footer();
    
    ?>

    Styling would be added to the bottom of default.css:

    /* =Page Templates
    -------------------------------------------------------------- */
    
    .page-template-template-fullwidth-php #container {
    	margin:0;
    	width:940px;
    }
    
    .page-template-template-fullwidth-php #content {
    	margin: 0 0 0 10px;
    	width:940px;
    }
    
    .page-template-template-fullwidth-php #comments {
        width:540px;
    }

    The styling for this could also go in layout css. It seems a bit redundant, but it might be more intuitive for people to look there. What do you think?

    I've tested it on a local version. If anyone sees any errors or has any comments, I'd appreciate the feedback. Perhaps Gene or Chris can decide if it's commit worthy. Thanks for reading.

    Posted 3 years ago #
  2. I use your code all the time for full-page templates... and always send people here who are looking for that info to your blog post. so it is such a common request that i'd be in favor. i'm in favor of a blog template too. as always, thanks for sharing so much cool stuff.

    Posted 3 years ago #
  3. Devin,
    I've also used this full-width template, which is the answer to many of my prayers. Another template I'd love is something analogous to Justin Tadlock's page-widgets.php, where an entire static page could be widgetized. I could see this particularly useful as a static front page.

    Posted 3 years ago #
  4. I looked at the hybrid framework again, and decided it probably makes more sense to name the template "page-fullwidth.php" (following Justin's conventions) to make it easier for people to switch between the two frameworks.

    I also changed my mind about where the css changes should go and put them into each of the individual layout stylesheets, since that's where the width of the #content area is defined and it does pertain more to layout. It's a duplication of code, but probably makes more sense overall.

    I committed the changes. I'm a bit new to SVN and am wondering if this should have been done as patch instead? Any guidance would be appreciated. If it all works out, I'll go ahead and build a blog template as well as any of the others there's a strong request for.

    Posted 3 years ago #
  5. Robo
    Member

    Great idea Devin. I too have wanted this functionality.

    Posted 3 years ago #
  6. This looks great! Thanks Devin. I saw the commit. It's good to see you in the mix.

    Posted 3 years ago #
  7. For the blog page template, I just copied over the code from Justin Tadlock's page-blog.php in hybrid.

    I know Woo themes was having a bit of trouble with paging in 3.0, their template-blog.php looks like this:

    <?php
    				// WP 3.0 PAGED BUG FIX
    				if ( get_query_var('paged') )
    					$paged = get_query_var('paged');
    				elseif ( get_query_var('page') )
    					$paged = get_query_var('page');
    				else
    					$paged = 1;
    				//$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
    
    	             query_posts("paged=$paged");
    	        ?>

    But this code (posted below) has been working fine for me. Unless someone sees a better way to do this, I'll commit the new template tomorrow:

    <?php
    /**
     * Template Name: Blog
     *
     * This template allows you to display the latest posts on any page in your site.
     *
     */
    
        // calling the header.php
        get_header();
    
        // action hook for placing content above #container
        thematic_abovecontainer();
    
    ?>
    
    		<div id="container">
    
    			<?php thematic_abovecontent(); ?>
    
    			<div id="content">
    
                <?php
    			$wp_query = new WP_Query();
    			$wp_query->query( array( 'posts_per_page' => get_option( 'posts_per_page' ), 'paged' => $paged ) );
    			$more = 0;
    			?>
    
    				<?php 
    
                	// create the navigation above the content
                	thematic_navigation_above();
    
                	// calling the widget area 'index-top'
                	get_sidebar('index-top');
    
                	// action hook for placing content above the index loop
                	thematic_above_indexloop();
    
                	// action hook creating the index loop
                	thematic_indexloop();
    
                	// action hook for placing content below the index loop
                	thematic_below_indexloop();
    
                	// calling the widget area 'index-bottom'
                	get_sidebar('index-bottom');
    
                	// create the navigation below the content
                	thematic_navigation_below();
    
                	?>
    
    			</div><!-- #content -->
    
    			<?php thematic_belowcontent(); ?> 
    
    		</div><!-- #container -->
    
    <?php 
    
        // action hook for placing content below #container
        thematic_belowcontainer();
    
        // calling the standard sidebar
        thematic_sidebar();
    
        // calling footer.php
        get_footer();
    
    ?>
    Posted 3 years ago #
  8. (Using a child theme with rev709)
    Ok, so Devin, I reviewed all the query_post docs in Codex, but this looks slightly different so I wasn't quite sure how to implement conditional argument parameters. I was hoping to have my blog page totally exclude posts in my custom taxonomies. How would I include that using your query up here?

    Posted 3 years ago #
  9. did you try the code? I thought it excluded the taxonomies by default

    Posted 3 years ago #
  10. Problem is, even if you add a post and assign it to a taxonomy, it gets assigned to category: Uncategorized. Which keeps it in the blogflow. So I would still have to exclude uncategorized posts which also belong to custom taxonomy. So we're back to square one: best practices for writing a new wp_query.

    Posted 3 years ago #
  11. Best article I've seen about query posts is here:
    http://www.binarymoon.co.uk/2010/03/5-wordpress-queryposts-tips/

    Codex ref here: http://codex.wordpress.org/Function_Reference/query_posts#Tag_Parameters

    Justin Tadlock's Taxonomy Tutorial:
    http://justintadlock.com/archives/2010/06/10/a-refresher-on-custom-taxonomies

    Justin says you can add a query var to your taxonomy. If you do that, I assume you can just exclude items in that taxonomy.

    Or, a simpler route might just be to change the name of "uncategorized" in your custom taxonomy to something like "untagged", "misc".

    Let me know if this helps.

    Posted 3 years ago #
  12. So question is how to write the function that alters the query for YOUR blog template.
    Given:

    <?php
    			$wp_query = new WP_Query();
    			$wp_query->query( array( 'posts_per_page' => get_option( 'posts_per_page' ), 'paged' => $paged ) );
    			$more = 0;
    			?>

    Where would I insert query_posts(array('category__not_in' => array(2,6)));? And how exactly does this get filtered in my functions.php file?

    Posted 3 years ago #
  13. Just a small correction on the CSS (after much head scratching when I couldn't get the code to work even though I knew it should :D)

    Instead of this,

    .page-template-template-fullwidth-php #container

    it's got to be this, because there's an extra 'page' in the name

    .page-template-template-page-fullwidth-php #container

    my amended code...

    /*Page Templates*/
    .page-template-template-page-fullwidth-php #container {margin:0; width:988px;}
    .page-template-template-page-fullwidth-php #content {margin: 0 0 0 10px; width:988px;}
    .page-template-template-page-fullwidth-php #comments {width:540px;}
    Posted 3 years ago #
  14. I would like to make certain blog posts full width. Is there a way to make a canned category template that is full width? So that if you picked the category "portfolio" (for example) then you'd get the sidebar-free category template: category-portfolio.php

    Posted 3 years ago #
  15. bluejpro- you could

    1. make a custom post type for portfolio items.

    2. there is definitely a plugin for custom post templates- that enables pretty much the same functionality as page templates, but for posts:
    http://wordpress.org/extend/plugins/custom-post-template/
    i've used it and like it, but you'd have to select it every time.

    3. it appears that the functionality you describe does exist:
    http://codex.wordpress.org/Category_Templates

    google is your friend

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.