Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #241840

    xperbranding
    Participant

    I will try to make this as clear as possible.

    I need different sidebars for each of my blog categories. I have advertisers that pay for banners on certain categories and not site-wide or throughout all blog categories.

    In the past I have done this by creating a PAGE using Visual Composer for each blog category, making the page 2 columns. Left column being blog displays that look exactly like the default archive pages list. Then the right column would be used for banners and such by advertisers. Normally in my experience, in VC when you click to add an ‘element’ to a page, there has been an option called ‘Blog’ that handles this perfectly. Then in the menus I would link to the PAGE for each blog category, not the option under ‘categories’.

    The final result of such a page in short code is this:

    [vc_row][vc_column width="1/1"][vc_blog title_size="heading-1" type="standard" blog_category="uncategorized" columns_count="1" posts_sort="date" posts_sort_order="DESC" posts_offset="0" content_output="excerpt" show_read_more="yes" enable_pagination="yes" number_of_posts="8" excerpt_length="30"][/vc_blog][/vc_column][/vc_row]

    Now I have got as far as adding the element to /themes/x/framework/functions/global/plugins/virtual-composer.php (code entered into virtual-composer.php is below). The below code has added the ‘Blog’ element to VC in the admin when creating a new page, but when I click the element to add it to the page it does not respond. So I am nearly there. What am I missing? The developer also said that this is already possible in VC, but I cannot find any such element so I am trying to create it myself. If there really is a way to accomplish what I am trying to do without messing with making a new element, then please explain. Here is the code I entered into the visual-composer.php file to add a new element that is displaying but does not respond to clicking it when trying to add it to a page.

    `/* Element: Blog
    ================================================== */
    $blog_categories = array();
    foreach (get_categories() as $category) {
    $blog_categories = array_merge( $blog_categories, array($category->name => $category->slug) );
    }
    vc_map( array(
    ‘name’ => ‘Blog’,
    ‘base’ => ‘vc_blog’,
    ‘show_settings_on_create’ => false,
    ‘is_container’ => true,
    ‘icon’ => ‘icon2-pencil’,
    ‘category’ => ‘Content’,
    ‘description’ => ”,
    ‘params’ => array(
    $parameter_widgetTitle,
    $parameter_widgetitleSize,
    array(
    “type” => “dropdown”,
    “class” => “”,
    “heading” => “Blog Type”,
    “param_name” => “type”,
    ‘description’ => ‘Select the display type for the blog.’,
    “value” => array(
    “Standard” => “standard”,
    “Mini” => “mini”
    )
    ),
    array(
    “type” => “checkbox”,
    “class” => “”,
    “heading” => “Blog Category”,
    “param_name” => “blog_category”,
    ‘description’ => ‘Choose the category for blog items.’,
    “value” => $blog_categories
    ),
    array(
    “type” => “dropdown”,
    “class” => “”,
    “heading” => “Columns Count”,
    “param_name” => “columns_count”,
    ‘description’ => ‘Select the columns count for the blog.’,
    “value” => array(
    “1” => “1”,
    “2” => “2”,
    “3” => “3”,
    “4” => “4”
    )
    ),
    array(
    ‘type’ => ‘textfield’,
    ‘heading’ => ‘Number of Posts’,
    ‘param_name’ => ‘number_of_posts’,
    ‘description’ => ‘The number of blog items to show per page. Leave blank to show all.’,
    ),
    $parameter_animation,
    array(
    “type” => “dropdown”,
    “class” => “”,
    “heading” => “Posts Sort”,
    “param_name” => “posts_sort”,
    “value” => array(
    “ID” => “ID”,
    “Date” => “date”,
    “Author” => “author”,
    “Title” => “title”,
    “Menu Order” => “menu_order”,
    “Random” => “rand”
    )
    ),
    array(
    “type” => “dropdown”,
    “class” => “”,
    “heading” => “Posts Sort Order”,
    “param_name” => “posts_sort_order”,
    “value” => array(
    “Ascending” => “ASC”,
    “Descending” => “DESC”
    )
    ),
    array(
    ‘type’ => ‘textfield’,
    ‘heading’ => ‘Posts Offset’,
    ‘param_name’ => ‘posts_offset’,
    ‘value’ => 0,
    ‘description’ => ‘The offset for the start of the posts that are displayed, e.g. enter 5 here to start from the 5th post.’,
    ),
    array(
    “type” => “dropdown”,
    “class” => “”,
    “heading” => “Content Output”,
    “param_name” => “content_output”,
    “value” => array(
    “Full Content” => “full”,
    “Excerpt” => “excerpt”
    )
    ),
    array(
    ‘type’ => ‘textfield’,
    ‘heading’ => ‘Excerpt Length’,
    ‘param_name’ => ‘excerpt_length’,
    ‘description’ => ‘The length of the excerpt for the posts.’,
    ),
    array(
    “type” => “checkbox”,
    “class” => “”,
    “heading” => “Show Read more Link”,
    “param_name” => “show_read_more”,
    “value” => array(
    “Yes” => “yes”
    )
    ),
    array(
    “type” => “checkbox”,
    “class” => “”,
    “heading” => “Enable Pagination”,
    “param_name” => “enable_pagination”,
    “value” => array(
    “Yes” => “yes”
    )
    ),
    $parameter_extraClass
    )
    ) );

    #241897

    Rad
    Moderator

    Hi there,

    Thanks for writing in.

    Yes, based on my understanding, your requirement is possible. Though, correct me if I’m wrong 🙂

    Because this requires a template change, I’d advise that you setup a child theme. This allows you to make code changes that won’t be overwritten when an X update is released. After your child theme is setup, please review how we recommend making template changes in Customization Best Practices.

    Then follow this https://theme.co/x/member/forums/topic/portfolio-menu/page/2/#post-134727

    Then simply add this another set of code at your child theme’s functions.php

    if ( ! function_exists( 'x_get_content_layout' ) ) :
      function x_get_content_layout() {
    
        $content_layout = x_get_option( 'x_layout_content', 'content-sidebar' );
    
        if ( $content_layout != 'full-width' ) {
          if ( is_home() ) {
            $opt    = x_get_option( 'x_blog_layout', 'sidebar' );
            $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
          } elseif ( is_singular( 'post' ) ) {
            $meta   = get_post_meta( get_the_ID(), '_x_post_layout', true );
            $layout = ( $meta == 'on' ) ? 'full-width' : $content_layout;
          } elseif ( x_is_portfolio_item() ) {
            $layout = 'full-width';
          } elseif ( x_is_portfolio() ) {
            $meta   = get_post_meta( get_the_ID(), '_x_portfolio_layout', true );
            $layout = ( $meta == 'sidebar' ) ? $content_layout : $meta;
          } elseif ( is_page_template( 'template-layout-content-sidebar.php' ) ) {
            $layout = 'content-sidebar';
          } elseif ( is_page_template( 'template-layout-sidebar-content.php' ) ) {
            $layout = 'sidebar-content';
          } elseif ( is_page_template( 'template-layout-full-width.php' ) ) {
            $layout = 'full-width';
          } elseif ( is_category() ) {
          	$layout = 'content-sidebar';
          } elseif ( is_archive() ) {
            if ( x_is_shop() || x_is_product_category() || x_is_product_tag() ) {
              $opt    = x_get_option( 'x_woocommerce_shop_layout_content', 'sidebar' );
              $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
            } else {
              $opt    = x_get_option( 'x_archive_layout', 'sidebar' );
              $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
            }
          } elseif ( x_is_product() ) {
            $layout = 'full-width';
          } elseif ( x_is_bbpress() ) {
            $opt    = x_get_option( 'x_bbpress_layout_content', 'sidebar' );
            $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
          } elseif ( x_is_buddypress() ) {
            $opt    = x_get_option( 'x_buddypress_layout_content', 'sidebar' );
            $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
          } elseif ( is_404() ) {
            $layout = 'full-width';
          } else {
            $layout = $content_layout;
          }
        } else {
          $layout = $content_layout;
        }
    
        return $layout;
    
      }
    endif;
    
    function ups_display_sidebar_v2( $default_sidebar ) {
    
      $q_object = get_queried_object();
      $sidebars = get_option( 'ups_sidebars' );
    
      foreach ( $sidebars as $id => $sidebar ) {
        if ( is_category() ) {
          
           $setting = get_option( "taxonomy_". $q_object->term_id );
           $default_sidebar = $setting['portfolio-category-sidebar'];
    
        }
      }
    
      return $default_sidebar;
    
    }
    
    add_filter( 'ups_sidebar', 'ups_display_sidebar_v2', 9999 );

    Save them and upload. Then go to your category at Admin > Posts > Categories and edit or add your category and set your sidebar created from Admin > Appearance > Sidebars.

    If you will continue using your version as VC Element, then it will be best if you can provide your url and admin login in private. So we could test it directly from your site. I checked your VC mapping and it works, though I’m not really sure what’s wrong and what’s your expected result.

    The suggested coding above will let you select sidebar for each category while you create or edit them. It’s the same as assigning sidebar at your taxonomies at Admin > Appearance > Sidebars. This is much efficient if you don’t want to rely on VC element per page (one page per category).

    Hope this helps 🙂

    #242241

    xperbranding
    Participant

    Great. I will give this a spin and see how it goes!

    #242338

    Christopher
    Moderator

    Let us know if you need further assist.