Skip Navigation

[Resolved] How to create general archive view

This support ticket is created 2 years, 5 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 3 replies, has 3 voices.

Last updated by Shane 2 years, 4 months ago.

Assisted by: Shane.

Author
Posts
#2236117

Sorry, I just lost in new documentation structure as it focused on using blocks.
I just want to add view to my site to show posts in different as a general archives as years, months, categories, etc. But I can;t find how to filter view output according to archive it will be used in.

So like show it in archive "Month: March 2020" or archive "Category: Category 1"

#2236289

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

You want to add a View to an archive (e.g. an archive for the term 'red' of the 'colour' taxonomy, at site.com/colour/red, which displays posts with the term 'red' assigned) and filter the View by the same condition so that it displays the same results that the archive itself does?

You could do that with a taxonomy archive as in my example by adding a query filter to your View for the taxonomy and specifying that the term comes from a shortcode attribute, and then where you insert the View (using a shortcode) you add the attribute and pass the value using a shortcode, e.g. wpv-taxonomy-slug.

See https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-taxonomy-slug

And see this page from the legacy documentation about how to pass values to Views filters: https://toolset.com/documentation/legacy-features/views-plugin/passing-arguments-to-views/

It's not possible to filter a View by publication date in the same way without writing some custom code, because there isn't a shortcode to output what the current date archive year and month are to pass to the View. So you would need to register custom shortcodes to return the year and the month, and then you could use those to provide the corresponding values.

#2245199

Thanks a lot, this works. But I have additional question - I want to output just name of the category, not full archive title. Like in category "Universities" I want to show on page <h1> included just "Universities" instead of full archive title ([wpv-archive-title]) as "Category: Universities". How could I do it?

#2245481

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Kirill,

You can do this by using the hook below.

add_filter( 'get_the_archive_title', 'wp_remove_post_type_prefix' );
/**
 * Remove prefix labels.
 * 
 * @param  string $title Current archive title to be displayed.
 * @return string        Modified archive title to be displayed.
 */
function wp_remove_post_type_prefix( $title ) {
  if ( is_post_type_archive('post_type') ) {
        $title = post_type_archive_title( '', false );
    }
    return $title;
}

Replace 'post_type' with the slug of the post type that you want this code to apply for or you can leave it empty.

This code can be added to Toolset -> Settings -> Custom Code and then activate it.

Please let me know if this helps.
Thanks,
Shane

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.