Unyson icon indicating copy to clipboard operation
Unyson copied to clipboard

Sidebar position issue for custom post types

Open dk-wordpress opened this issue 9 years ago • 19 comments

Hello!

I noticed that i can't change sidebar position for archive templates for custom post types (e.g. WooCommerce ) but it works fine for single products.

Is there any way to fix this please? Maybe, we can use https://codex.wordpress.org/Function_Reference/is_post_type_archive in sidebar extension?

Thank you again for this great framework :)

dk-wordpress avatar Dec 14 '16 11:12 dk-wordpress

Hello,

Please provide screenshots or video or the exact steps to reproduce (I am not an expert in Sidebars extension)

ghost avatar Dec 19 '16 14:12 ghost

Hi, @moldcraft , here are few steps (i'm using default Scratch theme in this case):

  1. On Appearance > WIdgets screen, add "Right sidebar" to All pages (works fine)

  2. Add Left Sidebar for Specific Pages > Shop (woocommerce plugin should be active). It doesn't change a sidebar position for this page

2016-12-19_16-46-32

Basically, i can't change sidebar position for this page even i choose Pages > Product or Category > Product category target

2016-12-19_16-44-36

This happens for all custom post types, not for WooCommerce Products only, e.g. it is not possible to change sidebar position for Custom Post Type / Archive page, try to change

Thank you :)

dk-wordpress avatar Dec 19 '16 14:12 dk-wordpress

I think the problem is here. I am trying to figure out how it works and how to fix it. If you know how, please share (or pull request).

ghost avatar Dec 21 '16 12:12 ghost

is missing more , own post types and woo shop homepage

I made my own plugin for widgets assignment and had issues with this ,

these are missing peaces I used in plugin wich will also fix this issue

method for custom post types

/**
 *  get post types for page info
*/		
protected function is_thz_post_type( $post = NULL )
{
	$all_custom_post_types = get_post_types();
	
	if( is_front_page() || is_search() || is_404() || is_home() ){
		return false;
	}
	
	// there are no custom post types
	if ( empty ( $all_custom_post_types ) ){
		return false;
		
	}

	$custom_types      = array_keys( $all_custom_post_types );
	$current_post_type = get_post_type( $post );

	// could not detect current type
	if ( ! $current_post_type ){
		return false;
	}

	return in_array( $current_post_type, $custom_types );
}

and these 2 inside the get_current_page_reset method

	if ( class_exists( 'WooCommerce' )  ) {
		if(	is_shop() ){
			$pageid = get_option( 'woocommerce_shop_page_id' );
			
			$data['type']     = 'pt';
			$data['sub_type'] = $data['type'].'_page';
			$data['id']       = $pageid ;
			$data['slug']	  = $data['sub_type'].'_'.$pageid ;	
			$data['setby']	  = 'is_shop()';
			
			if(in_array($data['slug'],$assigned_pages) || in_array($data['sub_type'],$assigned_pages)){			
				return $data;
			}			
			
		}	
	}


	if ( $this->is_thz_post_type() ){
		
		$data['type']     = 'pt';
		$data['sub_type'] = $data['type'].'_'.get_post_type();
		$data['id']       = get_queried_object_id();
		$data['slug']	  = $data['sub_type'].'_'.$data['id'];	
		$data['setby']	  = 'is_thz_post_type()';	
		
		if(in_array($data['slug'],$assigned_pages) || in_array($data['sub_type'],$assigned_pages)){			
			return $data;
		}		
	}

note I made my own output but you get the idea

danyj avatar Dec 21 '16 13:12 danyj

@moldcraft if you need my plugin as ref skype me , is much more extended than Unyson sidebars but the logic is based on get_current_page_preset() method

danyj avatar Dec 21 '16 13:12 danyj

@moldcraft Thank you for a great possibility to become Unyson tester :)

@danyj @moldcraft I suggest to add new group "Archives", because any of custom post type can have own archive page and it is not enough just one Archive category

I uploaded my changes for this repo https://github.com/ThemeFuse/Unyson-Sidebars-Extension here

https://drive.google.com/open?id=0Bz6XVdLE4r1fTG1FaDM4YTBlcU0

what were done:

  1. Added WooCommerce support
  2. Added Tag taxonomy support
  3. Added (any) Custom Post Type Archive support

please let me know what do you think

dk-wordpress avatar Dec 21 '16 17:12 dk-wordpress

this is how my plugin organizes the pages

http://take.ms/CvAyl

danyj avatar Dec 21 '16 18:12 danyj

@danyj looks good 👍

dk-wordpress avatar Dec 21 '16 19:12 dk-wordpress

@WPJobs I included your changes https://github.com/ThemeFuse/Unyson-Sidebars-Extension/commit/acd0053265cbaec79c4de4eac7b9ccc00ba1c6e7 Thank you

ghost avatar Dec 22 '16 11:12 ghost

Your changes fixes this issue please close it.

ghost avatar Dec 22 '16 11:12 ghost

Thank you so much, hope an update for Unyson will be released soon. Have a great day!

dk-wordpress avatar Dec 22 '16 11:12 dk-wordpress

@WPJobs Can you tell me please how can I test this ?

andronic90 avatar Dec 27 '16 09:12 andronic90

@andronic90 Sorry for late reply, i was on vacation :)

Try to install WooCommerce, then go to Appearance > Widgets and set any sidebar position for Shop page or WooCommerce category / tag. I tested the changes that i made and now it works without issues, please let me know if i can help more

dk-wordpress avatar Dec 30 '16 10:12 dk-wordpress

Hello @WPJobs , this works only for "Shop page", for categories and tags works and in previous version. For archives I tested inThe Core theme and this didn't work, for example for the archive /?post_type=post, for date - this is too archive, /?author=1 this is the same as archive. Please choose here only the posts that have archives : https://github.com/ThemeFuse/Unyson-Sidebars-Extension/commit/acd0053265cbaec79c4de4eac7b9ccc00ba1c6e7 , for example I think "Page" have no sense to include here https://www.screencast.com/t/G7268U2GN6jL .

andronic90 avatar Jan 02 '17 09:01 andronic90

@andronic90 you're right, please test this https://drive.google.com/open?id=0Bz6XVdLE4r1fTnFqdGFvZm8wVTQ, i removed Pages from archives.

Yes, previous version worked with Post archives, but not with third-party custom post types, for example, try WeDocs plugin, it was impossible to change sidebar for Docs post type, and now it fixed

Author archive page is already in the list, i believe it should be not moved to global Archives

dk-wordpress avatar Jan 03 '17 10:01 dk-wordpress

I downloaded the version that you send, and now the "archives" disappear from widgets list, please verify if the version that you send is the latest. Thank you

andronic90 avatar Jan 03 '17 11:01 andronic90

i'm so sorry, this is a right link https://drive.google.com/open?id=0Bz6XVdLE4r1fanR6STgwQkpicW8

dk-wordpress avatar Jan 03 '17 12:01 dk-wordpress

Hello @WPJobs , can you test now : https://github.com/ThemeFuse/Unyson-Sidebars-Extension , I extracted only post that have : "has_archive" and restore the "Archive Page" - for pages ad date, author and others pages

andronic90 avatar Jan 03 '17 15:01 andronic90

@andronic90, it works fine for me, thank you so much!

dk-wordpress avatar Jan 03 '17 16:01 dk-wordpress