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.
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/
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
to the
, 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.