WordPress.org

Ready to get started?Download WordPress

Forums

Full-width Page Template, No Sidebar Page Template (10 posts)

  1. Christine357
    Member
    Posted 10 months ago #

    The 'Full-width Page Template, No Sidebar Page Template' for Twenty Twelve; what part of it is what notes that the page will be full-width without the sidebar? I understand how to remove the sidebar, but trying to figure out how to make another custom template full-width as well when the sidebar is removed.

  2. alchymyth
    Forum Moderator
    Posted 10 months ago #

    start by creating a child theme; http://codex.wordpress.org/Child_Themes

    look into functions.php of the Twenty Twelve - there is a section which regulates the body_class() output according to the page templates....

    replicate that in your child theme.

  3. Christine357
    Member
    Posted 10 months ago #

    I believe I found the spot. In the WordPress codex I read that when creating functions.php it adds to the functions.php of the parent theme. This is the first time I am adding to that file though and what I tried to do is copy that whole function over it had a heart-attack and I knew I did something wrong so I reversed it. It said I couldn't redeclare the function, fair enough, but then how do I add to it or edit part of it in the child theme? Sorry to be going off-topic for a moment.

  4. alchymyth
    Forum Moderator
    Posted 10 months ago #

    how do I add to it or edit part of it in the child theme?

    create a new function with a different name;

    for example:

    add_filter( 'body_class', 'twentytwelvechild_body_class', 15 );
    
    function twentytwelvechild_body_class( $classes ) {
    	if ( is_page_template( 'your_custom_full_width_template_file_name.php' ) )
    		$classes[] = 'full-width';
       }
    }

    the 15 is added as priority to execute that filter after the parent theme's filter.
    http://codex.wordpress.org/Function_Reference/add_filter

  5. Christine357
    Member
    Posted 10 months ago #

    Thank you so much for your feedback and links to codex so I understand the code you are posting, specifically the filter part because I would've just added the function part and wonder why it's not working.

    Problem is tho, I am getting a PHP Error:

    Warning: join() [function.join]: Invalid arguments passed in /public_html/wp-includes/post-template.php on line 389

    Not sure why that is.

  6. alchymyth
    Forum Moderator
    Posted 10 months ago #

    my mistake - I copied this partially from my test site and forgot the 'return $classes;' line;

    corrected:

    add_filter( 'body_class', 'twentytwelvechild_body_class', 15 );
    
    function twentytwelvechild_body_class( $classes ) {
    	if ( is_page_template( 'your_custom_full_width_template_file_name.php' ) )
    		$classes[] = 'full-width';
       }
    return $classes;
    }
  7. Christine357
    Member
    Posted 10 months ago #

    The sidebar came back! Haha that doesn't even seem to make sense. It is using the same if-statement as the template with no sidebar and I removed the sidebar include from the bottom of my template! So weird.

  8. alchymyth
    Forum Moderator
    Posted 10 months ago #

    can you post the full code of your page template?
    and the code used in functions.php?

    does the page still use the page template?

  9. Christine357
    Member
    Posted 10 months ago #

    The page uses a Page-of-Posts Template I found here:

    http://www.transformationpowertools.com/wordpress/page-of-posts-template-for-twenty-twelve

    And with your help in another post I made a small change so that the posts show excerpts. Here is the full code for the template:

    <?php
    /**
     * Template Name: Page of Posts
     *
     * for a child theme of Twenty_Twelve
     */
    
    get_header(); ?>
    
            <div id="primary" class="site-content">
                    <div id="content" role="main">
    
                    <?php
                            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                            $args= array(
                                    'category_name' => 'Uncategorized', // Change this category SLUG to suit your use; or see for query parameters http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
                                    'paged' => $paged,
            'posts_per_page' => 3,
            'post_type' => 'post',
    );
                            query_posts($args);
                            if( have_posts() ) : ?>
    
                      <?php while ( have_posts() ) : the_post(); ?>
                           <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                <header class="entry-header">
                  <h1 class="entry-title">
                    <a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
                  </h1>
                  <?php the_post_thumbnail(); ?>
                </header><!-- .entry-header -->
    
                <div class="entry-summary">
                  <?php the_excerpt(); ?>
                </div><!-- .entry-summary -->
    
                <footer class="entry-meta">
                  <?php twentytwelve_entry_meta(); ?>
                  <?php edit_post_link( __( 'Edit', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?>
                </footer><!-- .entry-meta -->
      </article><!-- #post -->
                            <?php comments_template( '', true ); ?>
                          <?php endwhile; // end of the loop. ?>
    
                          <?php twentytwelve_content_nav( 'nav-below' ); ?>
    
                    <?php else : ?>
                      <article id="post-0" class="post no-results not-found">
                          <header class="entry-header">
                                <h1 class="entry-title"><?php _e( 'Nothing Found', 'twentytwelve' ); ?></h1>
                          </header>
                          <div class="entry-content">
                                <p><?php _e( 'Apologies, but no results were found. Perhaps searching will help find a related post.', 'twentytwelve' ); ?></p>
                                <?php get_search_form(); ?>
                          </div><!-- .entry-content -->
                      </article><!-- #post-0 -->
    
                    <?php endif; wp_reset_query(); ?>
    
            </div><!-- #content -->
        </div><!-- #primary -->

    And here is the code currently in my functions.php of my child theme:

    <?php
    
    add_filter( 'body_class', 'twentytwelvechild_body_class', 15 );
    
    function twentytwelvechild_body_class( $classes ) {
    	if ( is_page_template( 'homeTemplate.php' ) )
    		$classes[] = 'full-width';
    
    return $classes;
    }
    
    function my_theme_thumb() {
    set_post_thumbnail_size( 150, 150, true );
    }
    add_action( 'after_setup_theme', 'my_theme_thumb', 11 );
    
    ?>
  10. Christine357
    Member
    Posted 10 months ago #

    Well, I'm not sure what changed but it seems to be working now. The only thing is is just on that page the lil WordPress header thing at the top that links to the Dashboard and all that is missing and on all my pages is a title link of my site located above the Navigation (which is still above the header logo by default), and I am not sure why but I'll look into that.

    I might have confused it with my "blog" page that is normal, as I recently swapped the two and made my customized one the "home" page so I apologize about that. Thank you so much though for all your help!

Reply

You must log in to post.

About this Topic

Tags

No tags yet.