This topic has 2 replies, 3 voices, and was last updated 9 years by tstrickland415.

  • Author
  • #41030
     RY
    Participant

    Hi ,

    I want to create / add another custom sidebar for the archive page template which mean I create my own sidebar because Main sidebar already used for other page and I dont wanna use the same main sidebar to display. Currently I have registered new sidebar on child theme function.php. and I wanna know what’s the next step? Can you advice me on this.

    Thank you 🙂

    RY

    #41324
     Radu
    Moderator

    Hello,

    Put this code in your kleo-child functions.php

    COPY CODE
    
    
    if ( ! function_exists( 'archive_sidebar' ) ) {
    
    // Register Sidebar
    function archive_sidebar() {
    
    	$args = array(
    		'id'            => 'archive-sidebar',
    		'name'          => __( 'Archive sidebar', 'kleo_framework' ),
    	);
    	register_sidebar( $args );
    
    }
    
    // Hook into the 'widgets_init' action
    add_action( 'widgets_init', 'archive_sidebar' );
    
    }
    
    
    function add_before_my_siderbar() { ?>
       
    <?php
    if (is_archive()) { ?>
    <div class="sidebar sidebar-main col-sm-3 sidebar-right">
    	<div class="inner-content widgets-container">
    
    		<?php dynamic_sidebar('archive-sidebar'); ?>
    
    	</div><!--end inner-content-->
    </div><!--end sidebar-->
    <?php } ?>
    
    
    <?php
    }
    add_action( 'get_sidebar', 'add_before_my_siderbar' );
    

    Let me know if it works.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #42569
     tstrickland415
    Participant

    Hey Radu, thanks for the code, it works but it only adds the new sidebar above the main sidebar. Is there a way to remove the old sidebar from showing on the Archive page, allowing for only the archive sidebar to show?

    BTW, in case anybody searching is looking for ways to add different sidebars to different archive pages of custom post types, on line 23, instead of using is_archive() use is_post_type_archive(yourcustomposttype)

Viewing 3 posts - 1 through 3 (of 3 total)

The forum ‘KLEO’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?