Nathan
Forum Replies Created
-
Forum: Themes and Templates
In reply to: Add sidebar to front page twentytwelve template?Ok so OP was looking for a front page template which adds the Main Sidebar and both front page widget areas to the page
My last post was explaining how to create a new widget area for the front page which is a little off topic. I’ll leave the post for anyone looking to create a new widget area.
To answer the post, inside your child theme create a frontpage.php to override the twentytwelve frontpage.php template (or create a new template if your heart desires).
Paste the following code into the new template you created in the child theme. Go to the page you have set as your front page ( Pages -> Home ) and select the template from the template dropdown. The code below will create a “Front Page Template” so select that from the dropdown and things should work. I think OP may have been forgetting to select the template in the dropdown bc his code/logic appears correct.
<?php /** * Template Name: Front Page Template * * Description: A page template that provides a key component of WordPress as a CMS * by meeting the need for a carefully crafted introductory page. The front page template * in Twenty Twelve consists of a page content area for adding text, images, video -- * anything you'd like -- followed by front-page-only widgets in one or two columns. * * @package WordPress * @subpackage Twenty_Twelve * @since Twenty Twelve 1.0 */ get_header(); ?> <div id="primary" class="site-content"> <div id="content" role="main"> <?php while ( have_posts() ) : the_post(); ?> <?php if ( has_post_thumbnail() ) : ?> <div class="entry-page-image"> <?php the_post_thumbnail(); ?> </div><!-- .entry-page-image --> <?php endif; ?> <?php get_template_part( 'content', 'page' ); ?> <?php endwhile; // end of the loop. ?> </div><!-- #content --> </div><!-- #primary --> <?php get_sidebar(); ?> <?php get_sidebar( 'front' ); ?> <?php get_footer(); ?>
Forum: Themes and Templates
In reply to: Add sidebar to front page twentytwelve template?In the child theme.
- Create a new sidebar by creating file named ‘sidebar-front2.php’ or something similar inside your child theme.
- Paste the following into ‘sidebar-front2.php’
<?php /** * The sidebar containing the second set of front page widget areas. * * If no active widgets in either sidebar, they will be hidden completely. * */ /* * The widget area is triggered if any of the areas * have widgets. So let's check that first. * * If none of the sidebars have widgets, then let's bail early. */ if ( ! is_active_sidebar( 'sidebar-4' ) && ! is_active_sidebar( 'sidebar-5' ) ) return; // If we get this far, we have widgets. Let do this. ?> <div id="tertiary" class="widget-area" role="complementary"> <?php if ( is_active_sidebar( 'sidebar-4' ) ) : ?> <div class="third front-widgets"> <?php dynamic_sidebar( 'sidebar-4' ); ?> </div><!-- .fourth --> <?php endif; ?> <?php if ( is_active_sidebar( 'sidebar-5' ) ) : ?> <div class="fifth front-widgets"> <?php dynamic_sidebar( 'sidebar-5' ); ?> </div><!-- .fifth --> <?php endif; ?> </div><!-- #tertiary -->
- Create a functions.php inside your child theme and paste the following code.
/** * Register additional widget areas for front page. */ function mytheme_widgets_init() { register_sidebar( array( 'name' => __( 'Third Front Page Widget Area', 'twentytwelve' ), 'id' => 'sidebar-4', 'description' => __( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'twentytwelve' ), 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'after_widget' => '</aside>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', ) ); register_sidebar( array( 'name' => __( 'Fourth Front Page Widget Area', 'twentytwelve' ), 'id' => 'sidebar-5', 'description' => __( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'twentytwelve' ), 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'after_widget' => '</aside>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', ) ); } add_action( 'widgets_init', 'mytheme_widgets_init' );
- Inside front-page.php (or whichever template you’re wanting to add the widgets to add
<?php get_sidebar( 'front2' ); ?>
after the line<?php get_sidebar( 'front' ); ?>
but before `<?php get_footer(); ?>. The end of the file should look like this (or similar)<?php get_sidebar( 'front' ); ?> <?php get_sidebar( 'front2' ); ?> <?php get_footer(); ?>
- Add styling. I gave the new widget area an id of “tertiary”. Which I’m not sure if it is being used but you could change this id or just style using the classes. Or they can be changed, it’s up to you.
So basically what we did: create new widget area in the page template and register 2 new widgets in functions.php to be used in the new widget area.
Also, the new widget areas should be visible in the admin area now and you can drag and drop widgets into those areas.
I didn’t test any of this but the principles should be about correct and should be enough to figure out what needs to be done.
Forum: Fixing WordPress
In reply to: Can't create new post or page. Given 404 errorI was having a 404 error page come up when I try to view my posts also (fixed now). Pages were fine but I couldn’t view any post (altho it was fine in the db and I could output them to other pages).
I tried deleting .htaccess, resaving my permalink structure, etc etc.It came down to restoring the default permalink structure, then repairing the db. Then I could switch it to a new custom permalink structure.
Original permalink structure: /%pagename%
New structure: /%category%/%postname%/