WordPress.org

Ready to get started?Download WordPress

Forums

Twenty Twelve
Twenty Twelve Hardcode Sidebar (14 posts)

  1. Steven
    Blocked
    Posted 1 year ago #

    Yes, I am using a child-theme.

    my structure:
    + twentytwelve-child
    - style.css
    - sidebar.php
    - sidebar-front.php

    Twenty Twelve is designed so if there are no widgets in the sidebar then the page will not display the sidebar.

    I can add code into the sidebar, but it will only show up if the sidebar does. Which in order for the sidebar to appear it has to have a widget in it.

    What do I need to modify in order for me to be able to put the php and html directly into the sidebar file and not use widgets?

    I've checked the function.php and I've played with the sidebar files.

    So far no luck.

    Any help would be much appreciated.

    If you plan to tell me how poor of an idea this is please don't. Whether it is good or bad this is how I want to do it, and I'm simply hoping for a solution not a lecture.

    Thanks for your time.

  2. Try this: In your child theme's directory copy twentytwelve/sidebar.php into twentytwelve-child directory. Modify that file so it looks something like

    <?php
    /**
     * The sidebar containing the main widget area.
     *
     * If no active widgets in sidebar, let's hide it completely.
     *
     * @package WordPress
     * @subpackage Twenty_Twelve
     * @since Twenty Twelve 1.0
     */
    ?>
    <?php // Child theme mods here ?>
            <div class="widget-area" role="complementary">
                    <h3>Test Title Here</h3>
                    <p> More Test Text Here</p>
            </div><!-- #secondary -->
    <?php // End Child theme mods here ?>
            <?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
                    <div id="secondary" class="widget-area" role="complementary">
                            <?php dynamic_sidebar( 'sidebar-1' ); ?>
                    </div><!-- #secondary -->
            <?php endif; ?>

    That will put the new text on the bottom without any widgets. Play with the CSS to get it where you want it.

  3. martinjharvey
    Member
    Posted 1 year ago #

    Edit sidebar.php and delete the code. then add this code in its place -

    <div id="secondary" class="widget-area" rolw="complimentary">
         <!-- your static content here -->
    </div>

    This is probably the quickest way to achieve what you are looking for, although things like classes being used are now not relevant, as it is no longer a widget area, but if it bothered you it would be easy to duplicate an rename this to something more fitting.

    It's then pretty much the same for the sidebar-front.php, but if you just look at the lines of code after each is_active_sidebar(); statement, they are what you need to replicate and just remove any php before or inside them.

  4. Steven
    Blocked
    Posted 1 year ago #

    Thank you both very much. I've got Jan's code implemented into my sidebar.php. Since there are not any widgets being detected Twenty Twelve puts the following CSS into effect.

    body.template-front-page .site-content,
    body.single-attachment .site-content,
    body.full-width .site-content {
    width: 100%;
    }

    So the width needed to be altered. It works perfectly.

    Thanks again!

  5. You're welcome, glad to help.

  6. Andrew
    Forum Moderator
    Posted 1 year ago #

    Good work Steven, Martinjharvey & Jan :)

  7. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    alternative approach:

    depending on the 'active' sidebar status, the .full-width css body_class() is added with a filter function in functions.php near the end:

    if ( ! is_active_sidebar( 'sidebar-1' ) || is_page_template( 'page-templates/full-width.php' ) )
    		$classes[] = 'full-width';

    if you want to have a hard-coded sidebar, you would need to make the edits to sidebar.php, as already suggested by @Jan Dembowski and @martinjharvey;
    plus remove that .full-width class with a filter code in functions.php of the child theme (unless the 'full-width page template' is in use);

    example:

    add_filter('body_class','twentytwelvechild_body_classes',20);
    function twentytwelvechild_body_classes( $classes ) {
    
    	if( !is_page_template( 'page-templates/full-width.php' ) ) {
    		foreach($classes as $key => $value) {
    		if ($value == 'full-width') unset($classes[$key]);
          }
    	}
    	return $classes;
    }

    no edits to the css needed.

  8. Thanks! I like that solution better then editing CSS. Remove the unwanted full-width class is a neater solution.

  9. Steven
    Blocked
    Posted 1 year ago #

    Yeah, I had all ready looked into that because I didn't like relying on a CSS edit. I wanted the theme and template to function more normally.

    I agree it is a much better solution, and hope this thread helps out some other people.

    Thanks for the follow up.

  10. Steven
    Blocked
    Posted 1 year ago #

    @alchy I've been fiddling with the functions.php and I get nothing butt errors. What could I be doing wrong?

    The example you gave, where exactly did you intend for it to go?

    Also I am getting an error that I cannot use a new functions.php

    it is saying that the functions.php in the parent theme has all ready decalred twentytwelve_setup so the child theme can't declare and use it.

    Fatal error: Cannot redeclare twentytwelve_setup() (previously declared in /home/a6672073/public_html/wp/wp-content/themes/twentytwelve-child/functions.php:52) in /home/a6672073/public_html/wp/wp-content/themes/twentytwelve/functions.php on line 77

    What do I need to do in order to tell WP to use the child's function.php?

  11. It goes in the child theme's functions.php file. It should should not have anything in it except these lines.

    <?php
    
    add_filter('body_class','twentytwelvechild_body_classes',20);
    function twentytwelvechild_body_classes( $classes ) {
    
    	if( !is_page_template( 'page-templates/full-width.php' ) ) {
    		foreach($classes as $key => $value) {
    		if ($value == 'full-width') unset($classes[$key]);
          }
    	}
    	return $classes;
    }

    That should work like that. You don't need to copy the parent theme's functions.php file.

  12. Steven
    Blocked
    Posted 1 year ago #

    Thanks.

  13. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    functions.php in a child theme can be a bit tricky:

    the Codex is not very clear, that you must not create a functions.php in the child theme from a copy of functinos.php of the parent theme.

    start a new functions.php just with the opening php tags at the start of the first line:

    <?php

    then add functions or filter or whatever ...

    and close (optionally) with:

    ?>

    in the last line.

    (no characters or lines allowed before the first <?php and after the last ?>

    http://codex.wordpress.org/Child_Themes#Using_functions.php

    so if you just made a new functions.php in your child theme, the example posted by @Jan Dembowski is just right.

  14. Karl J.
    Member
    Posted 1 year ago #

    This sidebar gives me Problems too.
    I work with 2012. My Problem:
    1. I like to increase the size of "RECENT POSTS" aso
    2. Under META I would like to Keep some of These links. Can not find were these, I gess "dynamic links" location.

    What can I do?

    PS: My English in writing is not the best, sorry. Hope you can understand me.

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic

Tags

No tags yet.