I would change the sidebar on the "events" page. I created

Hello,

I would change the sidebar on the "events" page.
I created a new sidebar "calendrier" in this sidebar I have included calendar upcoming and I am currently trying to include a search by event category with Beautiful Taxonomy.
I would like to put this sidebar "calendrier" instead of the main sidebar, I know I need to add something in function.php in my theme, but what exactly?

Thanks

  • Michael Bissett
    • Recruit

    Hey @alexandre bousez, hope you're doing well today! :slight_smile:

    Instead of editing the functions.php for the theme, have you thought about using our Custom Sidebars Pro plugin to handle this instead?

    You could create a custom sidebar that would only show up on the event archive & single event pages, replacing the main sidebar. :slight_smile:

    How would that sound?

    Please advise,
    Michael

  • Ash
    • WordPress Hacker

    Hello @alexandre bousez

    I hope you are well today.

    You can do so with some custom code:

    add_action('wp', 'set_sidebar', 10);
    function set_sidebar() {
    	global $_wp_sidebars_widgets;
    	if( is_singular( 'incsub_event' ) ){
    		$_wp_sidebars_widgets['X'] = $_wp_sidebars_widgets['Y'];
    	}
    }

    X = the ID of the sidebar that will be replaced
    Y = the ID of the sidebar what will be appeared

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    To find sidebar ID, please check the screenshot. Here sidebar-1 is the ID.

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

  • alexandre bousez
    • Design Lord, Child of Thor

    Hello,

    Thanks Ashok for your comprehensive reply.
    I use this code in functions.php of my child theme

    add_action('wp', 'set_sidebar', 10);
    function set_sidebar() {
    	global $_wp_sidebars_widgets;
    	if( is_singular( 'incsub_event' ) ){
    		$_wp_sidebars_widgets['sidebar-1'] = $_wp_sidebars_widgets['sidebar-12'];
    	}
    }

    The ID 'sidebar-1' is the main sidebar and 'sidebar-12' the sidebar i want display on mysite.com/events/
    But nothing happens! The main sidebar dispaly again.

  • Ash
    • WordPress Hacker

    Hello @alexandre bousez

    Would you please send me login details and ftp details?

    To send me details, please use our contact form: https://premium.wpmudev.org/contact/

    Select: I have a different question
    Subject: Attn-Ash
    Details: Send all required details (admin info and ftp details) with a link of this thread, so that I can track.
    Also post a note here once you send the info.

    I will be happy to take a look :slight_smile:

    Cheers
    Ash

  • Ash
    • WordPress Hacker

    Hello @alexandre bousez

    Please check now.

    I have thought you were asking for single event page, sorry. I have set modified code in there to show in events archive page:

    add_action('wp', 'set_sidebar', 10);
    function set_sidebar() {
    	global $_wp_sidebars_widgets;
    	if( is_post_type_archive( 'incsub_event' ) ) {
    		$_wp_sidebars_widgets['sidebar-1'] = $_wp_sidebars_widgets['sidebar-12'];
    	}
    }

    If you want to show in single event page too, then add this:

    add_action('wp', 'set_sidebar', 10);
    function set_sidebar() {
    	global $_wp_sidebars_widgets;
    	if( is_post_type_archive( 'incsub_event' ) || is_singular( 'incsub_event' ) ) {
    		$_wp_sidebars_widgets['sidebar-1'] = $_wp_sidebars_widgets['sidebar-12'];
    	}
    }

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

  • alexandre bousez
    • Design Lord, Child of Thor

    Thank you very much, is ok now!
    I add || is_singular( 'incsub_event' ) and is ok for the tow types of pages.

    Now when i use Beautiful taxonomy i have a problem with the page called:

    I have included beautiful filter in a sidebar on the "events" and other pages. When from the dropdown list I chose an event category, and click on "filter" I returned to "... events/eab_events_category/Call-a-project/", "call-a-project" is the ID of the event category. This gives me a 404 error

    The reply of plugin author is

    the plugin uses WordPress builtin functionality to display taxonomy-specific posts directly on the cpt archive page. So the URL you're getting looks to be correct from that point.

    Do you know which archive template the plugin uses? It should use either archive.php or archive-events.php.

    is it possible that the "events" post type is named something else but wpmudev alters it's slug too late and not in the registration of the posttype?

    I can't reply to him.
    we use archive.php or archive-events.php?
    wpmudev alters it's slug too late and not in the registration of the posttype?

    Thanks again!

  • Ash
    • WordPress Hacker

    Hello @alexandre bousez

    Now when i use Beautiful taxonomy i have a problem with the page called:

    I am sorry, I didn't understand the issue. Did you use any code for this? Or any external plugin?

    Would you please elaborate the workflow and a link where I can check the issue live?

    Cheers
    Ash

  • Ash
    • WordPress Hacker

    Hello @alexandre bousez

    Events+ handles permalink in a different way. I have implemented some mode code, please check now.

    function curPageURL() {
     $pageURL = 'http';
     if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
     $pageURL .= "://";
     if ($_SERVER["SERVER_PORT"] != "80") {
      $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
     } else {
      $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
     }
     return $pageURL;
    }
    
    add_action( 'template_redirect', 'template_redirect_cb' );
    function template_redirect_cb() {
    	$url = curPageURL();
    	if ( strpos( $url,'eab_events_category' ) !== false ) {
    		$u = str_replace( "eab_events_category/", "", $url );
    		$u = str_replace( "events/", "blog/events/", $u );
    		wp_redirect( $u );
    	}
    }

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

  • alexandre bousez
    • Design Lord, Child of Thor

    You can again help me...

    In the result of Beautyful taxonomy pages above views (eg /blog/events/appels-a-projets/), i would like to swap the sidebar, like in the events page, what is the condition to add at
    if( is_post_type_archive( 'incsub_event' ) || is_singular( 'incsub_event' ) )

    I think is a mixt of the two codes...
    I try that without success

    add_action('wp', 'set_sidebar', 10);
    function set_sidebar() {
    	global $_wp_sidebars_widgets;
            $url = curPageURL();
    	if( is_post_type_archive( 'incsub_event' ) || is_singular( 'incsub_event' ) || strpos( $url,'eab_events_category' ) !== false) {
    		$_wp_sidebars_widgets['sidebar-1'] = $_wp_sidebars_widgets['sidebar-12'];
    	}
    }

    Thanks again!

  • alexandre bousez
    • Design Lord, Child of Thor

    Hello Ashok

    Thanks for your links i know those.

    I was thinking of how to find information as the page "type" (post_type_archive, singular, tax),the page "name" (incsub_event incsub_event eab_events_categor) the id, that sort of thing in wordpress. Some specific tips ....

    Best regards

  • Ash
    • WordPress Hacker

    Hello @alexandre bousez

    Sure, here you can take a look:
    http://codex.wordpress.org/Function_Reference/is_post_type_archive
    http://codex.wordpress.org/Function_Reference/is_singular
    http://codex.wordpress.org/Function_Reference/is_single
    http://codex.wordpress.org/Function_Reference/is_page
    http://codex.wordpress.org/Function_Reference/is_tag
    http://codex.wordpress.org/Function_Reference/is_tax
    http://codex.wordpress.org/Function_Reference/is_category

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.