Skip Navigation

[Resolved] Different archive views

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.

This thread is resolved. Here is a description of the problem and solution.

Problem:

I have a custom post type, and want to display the archive in two different ways, showing different fields of the archive

e.g.

Archive 1 grid:
Title/Link
Image
CPT Data field A
CPT Data field B

Archive 2 grid:
Title/Link
Image
CPT Data field C
CPT Data field D

Is this possible? Looks like I can only have one archive layout assigned to a CPT at a time, unless I'm missing something. My google-fu has let me down...

Solution:

please try Layouts filter hook "get_layout_id_for_render", like this:

add_filter( 'get_layout_id_for_render', 'board_members_archive_func', 999, 2 );
function board_members_archive_func( $layout_id, $layout) {
    if ( isset($_GET['board-members']) && $_GET['board-members'] == 1) {
        $layout_id = 1390;
        //print_r ("yes");      
    }
    else {
        //print_r ("no");
    }
    return $layout_id;
}

Relevant Documentation:

This support ticket is created 6 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 12 replies, has 2 voices.

Last updated by Luo Yang 6 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#610783

I have a custom post type, and want to display the archive in two different ways, showing different fields of the archive

e.g.

Archive 1 grid:
Title/Link
Image
CPT Data field A
CPT Data field B

Archive 2 grid:
Title/Link
Image
CPT Data field C
CPT Data field D

Is this possible? Looks like I can only have one archive layout assigned to a CPT at a time, unless I'm missing something. My google-fu has let me down...

Thanks...

#610957

Dear Ivan,

Yes, it is expected result, but you can use Views filter hook "wpv_filter_force_wordpress_archive" to change it, see our document:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_wordpress_archive
Filters the ID of the WordPress Archive to be used on a given archive loop.

For example, this thread:
https://toolset.com/forums/topic/possible-to-have-multiple-templates-for-archives/#post-606155

#611394

Thanks. In my scenario, I'll be using a different archive if the post type is assigned a certain category. It looks like your example thread code is almost perfect for my use case, so thanks for the link! I'll leave the ticket open for now and will check in when I (hopefully) get it working to close the ticket.

I take it the hook can go in theme functions.php?

#611411

I'm missing something fundamental. I ended up cloning my main layout. I changed the copy by adding a query filter in the archive cell that shows only those cells where mytaxonomy=myvalue. If I assign the original layout to the archive, it shows all cells. If I assign the modified copy, it shows the filtered view I want. Now all I need is a way to display both layouts.

I'm not sure if I can do this with a url - everything I've read says I cant easily do domain.com/CPT/taxonomy/taxonomy-value format urls out of the box.

Maybe I can have urls
domain.com/CPT
and
domain.com/CPT?showalternatelayout=1 (or similar)
and use the GET variable in the wpv_filter_force_wordpress_archive hook to force the alternate layout?

I'm guessing there's a better solution? Thanks for sticking with me - I'm learning!

#611619

As you can see, it needs custom PHP codes, to avoid any misunderstanding, please elaborate the question with more details:
Now all I need is a way to display both layouts.

For example there are two WordPress Archive in your website:
- WordPress Archive A
- WordPress Archive B

Where (what page) and in what condition do you want to display the WordPress Archive A?
Where (what page) and in what condition do you want to display the WordPress Archive B?

Please describe detail steps to duplicate same problem, I need to test it in my localhost, thanks

#611719

Thanks for getting back to me.

I have custom post type student, with archive view showing grid of all students, I have taxonomy "student status" where some students are assigned "board member" category. I've successfully created the archive to show all students and the archive with query filter to show only students that are board members. By assigning one at a time to be the archive view, I've demonstrated that both work as I want them. I now need to be able to access them as two distinct locations from the menu - e.g. student menu item and board member menu item.

The only thing I can think of at the moment is a GET variable in the URL so

hidden link

shows the regular archive view

and

hidden link

shows the second archive view with the query filter. I would use functions.php to retrieve GET variable and if set, use wpv_filter_force_wordpress_archive to return the query filter archive id. This doesn't seem like the most elegant solution though.

Hope it makes sense?

#611723

Please try this:

add_filter( 'wpv_filter_force_wordpress_archive', 'board_members_archive_func', 99, 2 );
function board_members_archive_func( $wpa_assigned, $wpa_loop ) {
    if ( isset($_GET['board-members']) && $_GET['board-members'] == 1) {
        $wpa_assigned = 1234;
    }
    return $wpa_assigned;
}

replace 1234 with your second archive view's ID

#611768

Hi. No luck, I'm afraid. I've added debug logic to your code, and verified that the code is retrieving the GET variable correctly and setting/returning the layout ID of the query filtered layout (1390) that I got from Toolset Layouts ( wp-admin/admin.php?page=dd_layouts ). However the original layout is still used to show the archive.

Looking again at the docs and your reply, I see that maybe the hook in question acts on WordPress Archives, not layouts? I cloned the main view and put the same query filter on it, and set the id in the to the new WP Archive ID instead. Still no luck.

#612047

Since it is a custom PHP codes problem, please duplicate same problem in a test site, and fill below private detail box with login details and FTP access, also point out the problem archive page URL, and where I can edit you PHP codes, I need a live website to test and debug, thanks

#612622

Thanks for the details, I am checking it in your website, will feedback if there is anything found

#612624

There is a misunderstanding, the "wpv_filter_force_wordpress_archive" only works for the Views wordpress archive, but in your case, it needs to assign different layout, please try Layouts filter hook "get_layout_id_for_render", like this:

add_filter( 'get_layout_id_for_render', 'board_members_archive_func', 999, 2 );
function board_members_archive_func( $layout_id, $layout) {
    if ( isset($_GET['board-members']) && $_GET['board-members'] == 1) {
        $layout_id = 1390;
		//print_r ("yes");		
    }
	else {
		//print_r ("no");
	}
    return $layout_id;
}

#613323

I appreciate your help and patience in helping me to resolve this matter.

#613593

You are welcome

The forum ‘Types Community Support’ is closed to new topics and replies.