Results 1 to 2 of 2

Thread: Help creating widgets for each category

  1. #1
    Thread Starter
    masandra's Avatar
    Join Date
    Apr 2013
    Location
    Cardiff United Kingdom
    Posts
    131
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Help creating widgets for each category

    I came across a post by athora, which was posted in 2013. Help creating widgets for each category.

    Code originally from
    http://bavotasan.com/2012/create-wid...-in-wordpress/

    I pasted the code below into functions.php


    add_action( 'widgets_init', 'category_sidebars' );
    /**
    * Create widgetized sidebars for each category
    *
    * This function is attached to the 'widgets_init' action hook.
    *
    * @uses register_sidebar()
    * @uses get_categories()
    * @uses get_cat_name()
    */
    function category_sidebars() {
    $categories = get_categories( array( 'hide_empty'=> 0,'taxonomy'=> APP_TAX_CAT ) );

    foreach ( $categories as $category ) {
    register_sidebar( array(
    'name' => $category->cat_name,
    'id' => $category->category_nicename . '-sidebar',
    'description' => 'This is the ' . $category->cat_name . ' widgetized area',
    'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    'after_widget' => '</aside>',
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>',
    ) );
    }
    }



    Great, all the subcategories show in the widgets admin, but I think that the second piece of code, which is put into the sidebar.php to call the appropriate sidebar on my category pages is not working for Classipress, this code was originally for wordpress.

    Do anyone know what changes need to be made to the code below, which has to be placed into the sidebar.php to enable it to work with Classipress?


    $sidebar_id = ( is_category() ) ? sanitize_title( get_cat_name( get_query_var( 'cat' ) ) ) . '-sidebar' : 'sidebar';
    dynamic_sidebar( $sidebar_id );


    I tried replacing dynamic_sidebar() function in that sidebar.php file with the code above but this did not work.

    I would really like to get the sidebars on all my subcategories but am stuck with this code.

    Any help would be welcome.
    Thanks.

  2. #2
    Thread Starter
    masandra's Avatar
    Join Date
    Apr 2013
    Location
    Cardiff United Kingdom
    Posts
    131
    Thanks
    18
    Thanked 0 Times in 0 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Help creating widgets for each category
    By athora in forum ClassiPress General Discussion
    Replies: 2
    Last Post: August 27th, 2013, 06:34 PM
  2. Creating title tags for job-category pages
    By ugooliver in forum Simplux
    Replies: 2
    Last Post: July 11th, 2013, 04:28 PM
  3. Styling Category Dropdown when Creating New Listing
    By kdubose in forum ClassiPress General Discussion
    Replies: 1
    Last Post: June 22nd, 2013, 01:21 AM
  4. Samcy How to ad category icons without creating a child theme????
    By enrique in forum ClassiPress General Discussion
    Replies: 4
    Last Post: January 6th, 2013, 11:30 AM
  5. Creating two separate category list
    By canadawebservices in forum ClassiPress General Discussion
    Replies: 3
    Last Post: December 7th, 2012, 12:39 PM