Skip Navigation

[Resolved] Possible to have multiple templates for archives?

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

Problem:
I have this link as a button on my homepage to view my editors pick's: https://site-URL/category/editors-picks

After clicking that link I get directed to a page that displays the archives for editors picks. I have an archive template created and set for categories, but is it possible to have a different template display for the category editors picks, while keep the template for the other categories archives?

Solution:
You can try with Views filter hook "wpv_filter_force_wordpress_archive".

For example, use above filter hook to trigger a custom PHP function, in this function, check if current page is the editors pick's term archive page, then return another specific archive view ID.

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_wordpress_archive

This support ticket is created 6 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

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 13 replies, has 3 voices.

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

Assisted by: Luo Yang.

Author
Posts
#605209

Support,

I have this link as a button on my homepage to view my editors pick's: hidden link

After clicking that link I get directed to a page that displays the archives for editors picks. I have an archive template created and set for categories, but is it possible to have a different template display for the category editors picks, while keep the template for the other categories archives?

Thank,
Chuck

#605326

Dear Chuck,

You can try with Views filter hook "wpv_filter_force_wordpress_archive".

For example, use above filter hook to trigger a custom PHP function, in this function, check if current page is the editors pick's term archive page:
https://developer.wordpress.org/reference/functions/is_tax/
Then return another specific archive view ID.

More help:
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.

#605475

I understand.

As I'm not a PHP writer, can you assist me with this?

Assuming it would look something like this:

add_filter( 'wpv_filter_force_wordpress_archive', 'my_callback_function', 30, 2 );

function is_tax( $taxonomy = '', $term = '' ) {
    global $wp_query;
 
    if ( ! isset( $wp_query ) ) {
        _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
        return false;
    }
 
    return $wp_query->is_tax( $taxonomy, $term );
}

The ID for the editors-picks archive is: 10054

Appreciated,
Chuck

#605613

For example, you can try to add below codes into your theme/functions.php:

add_filter( 'wpv_filter_force_wordpress_archive', 'editors_picks_archive_func', 30, 2 );
function editors_picks_archive_func( $wpa_assigned, $wpa_loop ) {
    if ( is_tax( 'category', 'editors-picks' ) ) {
        $wpa_assigned = 10054;
    }
    return $wpa_assigned;
}
#605621

Thanks Luo.

The code looks promising, but did not return the desired result.

Do I need to set a Loop Selection or Query Filter? I assume this function picks the up automatically, so they should be left blank?

Thanks,
Chuck

#605636

It is only an example, you will need to customize the codes according to your website site setttings, Since it is a custom codes problem, if you still need assistance for it, please provide a test site with same problem, fill below private message box with login details and ftp access, I need a live website to test and debug

#605640

HI Luo. can you look ito this topic pls.
https://toolset.com/forums/topic/code-not-valid-2/

#605704

I tried the FTP access you provided above, it is not valid, I get this error:
Response: 530 Login authentication failed

please check it, make sure it is valid, then update this thread. thanks

#605727

Luo,

Those credentials are correct. They're autosaved in toolset. Can you try again?

#605737

Yes, I tried lots of time, it is not valid for me, here is the FTP logs:
Command: USER info@artilliodesigns.com
Response: 331 User info@artilliodesigns.com OK. Password required
Command: PASS **********
Response: 530 Login authentication failed
Error: Critical error: Could not connect to server

Please check it

#605836

Luo,

Are you able to view my login info from this post: https://toolset.com/forums/topic/pagination-to-only-show-single-view-on-next-page/

You'll see it's the same. I would double check case sensitivity and make sure you're including the period for the end of the password.

Let me know if you're having trouble.

Regards,
Chuck

#606155

The FTP access is not valid, so I edit your PHP codes in the wordpress dashboard-> Appearance-> Editor, to below:

add_filter( 'wpv_filter_force_wordpress_archive', 'editors_picks_archive_func', 99, 2 );
function editors_picks_archive_func( $wpa_assigned, $wpa_loop ) {
    if ( is_category( 'editors-picks' ) ) {
        $wpa_assigned = 10054;
    }
    return $wpa_assigned;
}

Please test again, check if it is fixed or not, more help:
https://developer.wordpress.org/reference/functions/is_category/

#607360

Luo,

This worked!

Thank you,
Chuck

#607389

You are welcome