gantry / gantry5

:rocket: Next Generation Template / Theme Framework
http://gantry.org
1.03k stars 203 forks source link

Wordpress Outline Assignment to a specific Post Type #1298

Closed horch004 closed 8 years ago

horch004 commented 8 years ago

You can assign an outline to one or more posts of a particular post type. Let say I want all pages to conform to a custom outline. At that outline's assignment page you can check all pages. But when a new page is created it's not automaticaly assigned to that outline.

An other problem is/was that you can not easily assign an archive page of a specific post_type to an outline. With Pods I have custom post types with their own archive pages. For some of these archive pages I wanted a different outline.

I managed to create a Posttype Integration. This integration takes all post_types (show ui and public) and gives me/you the ability to assign an outline to a specific post_type. The post_type archive page can be checked as well as just one checkbox/slider to assign all single items/posts belonging to that post_type. So, now every (old and new) item/post of a specific post_type gets assigned to the outline and/or the archive page gets assigned to the outline.

At first, the path to the new Integration was: /wp-content/plugins/gantry5/src/classes/Gantry/Wordpress/Integration/PostType But, after an update of Gantry 5 my custom Integration was gone. So, this is not the ideal place for my integration.

I already have a custom Wordpress plugin installed. So, from within this plugin I managed to register the PostType Integration to Gantry in an after_theme_setup action hook. I think this is not an ideal way of registering a custom Integration. At least it would be great to have a filter or action hook in the Grantry/Framework/Gantry::init function. Better would be to automatically register custom Integrations from the custom theme folder structure somewhere.

I attached the zip with my custom Integration (when it still resided in the Gantry Integration folder). Maybe it can be integrated in the Gantry framework as a AssignmentsPosttype class.

For now this works great for me.

Posttype.zip

n8115 commented 8 years ago

horch004 - THANK YOU for posting your solution, I just spent hours trying to find a solution to assigning an outline to a custom post type, was about to give up and find a less-ideal work-around.

newkind commented 8 years ago

@horch004 - Thank you for that! I'll play with it today :)

AmibeWebsites commented 8 years ago

@newkind Are you likely to implement this prior to 5.3.0? The solution posted is a little too technical for me so I'll use another sneaky workaround for now but I could certainly use this on pretty much every website I'm involved with as they all have custom post types.

horch004 commented 8 years ago

@dudewithamood I created a simple plugin for the solution. The plugin registers the custom Integration with the Gantry5 framework. I use it myself now for the time being. Have fun :-).

Plugin - gantry5_integrations.zip

AmibeWebsites commented 8 years ago

Thank you @horch004 - that helps me greatly.

w00fz commented 8 years ago

Related to #928 and #771

horch004 commented 8 years ago

I extended my gantry5_integrations plugin with a BuddyPress Integration. BuddyPress is added to the Page Context (assign the outline to BuddyPress as a whole) and the different components of BuddyPress are added as separate assignment options.

@newkind Is the BuddyPress Integration something to include in the Integrations folder like WooCommerce?

gantry5_integrations.zip

mahagr commented 8 years ago

I think we want to have built-in support for both of them. Thank you!

We will likely delay our G5.3 release to get a few more fixes and features in and this is certainly one of the features we're going to look at.

newkind commented 8 years ago

@mahagr BuddyPress and bbPress still needs their own component support so actually code from @horch004 will be useful. Thanks @horch004 I'll go through your code :)

horch004 commented 8 years ago

Hi @newkind,

I have extended the BuddyPress Assignment to support assignments to Member Types and Groups. The rules check if the current loggedin user is of a specific member type and/or the user is member of a specific group.

I am not sure if these assignments options are interesting to use in the real world. But they can be added for most flexibility.

If you are interested you can take a look at the attached file. Assignments.zip

Because I don't use it (for now) in my real world website, It is not a must for me to be implemented. .

horch004 commented 8 years ago

@newkind I made a little change in the priority of the member type and group. After some testing it seemed better to assign a low priority so that other assignments may overrule. With the default priority of 4 the outline with the homepage assignment gets overruled. With a priority of 1, the outline with the homepage assignment wins. Other pages with a outline member type or group assingment show up correctly.

Assignments.zip

newkind commented 8 years ago

Thanks very much @horch004 !!! That's awesome! Once we release our new premium template I'll finish integrating your code change! I'm sure that community folks will highly appreciate that just like me :)

When this will be all integrated and you'll want to contribute some fixes/enhancements/code, can I ask you please to open a Pull Request for the next time ? This would be easier to do then :)

One more time thanks!

horch004 commented 8 years ago

Hi @newkind , I already have a small fix in the Assignments.php file after the line: $user_member_types = bp_get_member_type($user_id, false);

There has to be a check if the $user_member_types variable is not empty. If the currently loggedin user has no member type specified this variable is empty and not an array.

Can I open a Pull Request already?

w00fz commented 8 years ago

I think you should @horch004, we haven't integrated your change yet and if it's in a PR it will be easier to see the code diff and to merge it in the develop branch as soon as we can.

Thanks!

newkind commented 8 years ago

@horch004 are you on our Gitter chat ?

newkind commented 8 years ago

@horch004 Ok, I modified your code a little bit to add extra sections to the Post Type cards instead of creating separate cards - much cleaner and takes less space. I have also set it to skip built-in post types as they should be played with using 'Context' card.

Can you all please test it and report if everything's fine ?