Skip Navigation

[Résolu] Customize only one WordPress category archive

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 support ticket is created Il y a 9 années et 3 mois. 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 2 réponses, has 2 voix.

Last updated by scottD-2 Il y a 9 années et 3 mois.

Assisted by: Luo Yang.

Auteur
Publications
#268277

I am trying to customize the view of one specific WordPress category archive page. For example, the site has a category called "Locations", which are regular WordPress blog posts (not a custom post type). Instead of the standard category layout (newest posts first, etc.), I want to display the list of Locations blog posts alphabetically.

All other categories should be displayed the way the theme normally shows them, in order of when the posts were made.

In the past I modified the loop in archive.php to display the category alphabetically like this:

<?php if (is_category('locations')):
				$args = array( 'posts_per_page' => -1, 'orderby'=> 'title', 'order' => 'ASC', 'cat' => 9 );
				$locationsposts = get_posts( $args ); ?>
				<ul>
					<?php foreach ( $locationsposts as $post ) : setup_postdata($post); ?>
						<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
					<?php endforeach; ?>
				</ul>
			<?php else: ?>
			// do the regular loop for all other categories

I was just curious to see if Views had a way of modifying the archive page for just one category.

#268370

You can try Views filter hook wpv_filter_force_wordpress_archive:

Description
Filters the ID of the WordPress Archive to be used on a given archive loop.
https://toolset.com/documentation/user-guides/views-filters/wpv_filter_force_wordpress_archive/

#268532

Thanks for the reply. I don't think that was exactly what I was looking for. Although if the documentation had a little more detail it might have worked. It seemed like no matter what I did in the function, the WordPress Archive layout (from Views) was being applied to every category archive page.

Regardless, I have a working solution now by using a custom View that uses the following settings:
Content selection: Posts
Query Options: Don't include current page...
Ordering: Order by Post Title Ascending
Limit & Offset: No limit, skip none
Query Filter: Select posts with taxonomy: Categories is One of these (Locations)

Then in the layout HTML/CSS/JS I added

[wpv-post-link]<br />

to the

<wpv-loop>

, which is all I want to display for this category.

Next I created a Locations page and added the

[wpv-view name="Locations Page"]

shortcode. In my site's navigation bar I replaced the link to the Locations category archive page with a link to the Locations page I just created.

Again, this isn't exactly what I wanted as I would like to have control over the archive page layout.

As an additional feature request, it might be nice to have a little more fine-tuned control over which WordPress Archive gets modified. Perhaps instead of listing only Categories and Tags under Taxonomy Archives, there could be an option to select "All Categories" or "All Tags" (which would be the same as the current behavior), and another option to specify which category or tag that the archive layout is applied to.

Le forum ‘Types Community Support’ est fermé à de nouveaux sujets et réponses.

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