Archive-Pro-Matic Pretty URL Rewrite

The goal is to change an ugly archive url into a pretty url. For example here is a quarterly custom post type archive:

The links are in a format of:

https://spacedonkey.de/date/2012/?q=4&post_type=monkey

And they would look better with something like:

https://spacedonkey.de/monkey/2012/Q4

To accomplish this, first the Add rewrite rules must be checked on the Archive-Pro-Matic settings page:

After the CPT Rewrite Rules has been checked and saved. It might be necessary to flush the rewrite rules by simply navigating to:
Dashboard > Settings > Permalinks – do nothing, and re-save the permalink settings.

Second a custom url rewrite function must be added to the child-theme’s function.php file. This function uses a new filter that has been added to manually overwrite the url that archive-pro-matic uses:

add_filter('apm_archive_link', 'pretty_my_archive_url');
function pretty_my_archive_url($url){
    $url_args = explode('?', $url);
    if(!empty($url_args[1])){
       parse_str($url_args[1], $args);
       if(!empty($args['year']) && !empty($args['q'])){
          $url = $url_args[0].$args['year'].'/Q'.$args['q'].'/';
       }
    }
    return $url;
}

Now, when we display a quarterly archive for a custom post type, the urls are prettier:

[archives type="quarterly" post_type="donkey" /]

And here is a test of just using the standard yearly archive for a custom post type:

[archives post_type="donkey" /]

Archive Pro Matic Exclude Single Cat

Test to see if a single category can be excluded from an archive list.

[archives type="monthly" cat_id="-51"/]

Archive-Pro-Matic Monthly Sub Post-By-Post

This is a test of a monthly archive that displays a sub-list of post-by-post archives.

[archives type="postbypost" sub_options="true" limit="10"/]

Categories

Here are examples of limiting by category. First, using cat_id

[archives type="postbypost" sub_options="true" cat_id="55" limit="10"/]

Taxonomies

Next, Using taxonomy and term. This pair can be used for any taxonomy, including category:

[archives type="postbypost" sub_options="true" taxonomy="category" term="archive-pro-matic" limit="10"/]

Archive-Pro-Matic Birthmonth Grid

Normally archives will be shown in a unordered list (ul) element:

[archives type="birthmonth" order="ASC" /]

However, this (or any) unordered list can be formatted using css. Here is an example of how to turn the list in to a grid using the CSS columns attribute:

First, we define a UL class that we can later assign:

ul.grid {
    list-style: none;
    columns: 4;
}

Now we just need to assign this class to our list:


[archives type="birthmonth" order="ASC" class="grid" /]

Archive-Pro-Matic Decade Filters

As of Archive-Pro-Matic version 1.1.10 we have added two filters two filters for the decade archives list:

Filter: apm_decade_archive_list


apm_decade_archive_title is used to display how the decade appears in the archive list. The default list is YYYY’s, for example:
2010’s

2000’s

apply_filters('apm_decade_archive_list', $text, $decade);

This filter can be used to change how the decade list is displayed by adding the following to the function.php file in the child-theme.

add_filter( 'apm_decade_archive_list', 'list_decade_range', 10, 2 );
function list_decade_range($text, $decade){
   $text = $decade.' - '.($decade + 9);
   return $text;
}

Filter: apm_decade_archive_title

apm_decade_archive_title is used to display the title of the decade archive page. The default title is The YYYY’s for example:
The 2000’s

apply_filters('apm_decade_archive_title', $title, $decade);

And would be used by adding the following to the child theme’s function.php file:

add_filter( 'apm_decade_archive_title', 'decade_range_title', 10, 2 );
function decade_range_title($title, $decade){
   $title .= ' ('.$decade.' - '.($decade + 9).')';
   return $title;
}

Here is an example shortcode that will list an archive of posts by decade:

[archives type="decade"/]
this is a caption


Archive-Pro-Matic Birthday and Birthmonth types

This is a test of two new types of Archive-Pro-Matic archive lists:
Birthday: Show all posts published on the same day of the year
Birth Month: Show all post published on the same month, regardless of year

Birth Month

[archives type="birthmonth" order="ASC" /]

Birthday

[archives type="birthday" order="ASC"/]
[archives type="birthday" order="ASC" sub_options="true" sub_order="ASC"/]
[archives type="birthday" order="ASC" sub_options="true" sub_order="ASC" show_empty="true"/]
[archives type="birthday" order="ASC" sub_options="block" sub_order="ASC" show_empty="true" tag="div" sub_ul_class="my_slim_ul" li_class="block_archive_item" empty_class="grey"/]

Archive-Pro-Matic Advanced Category Archives

Building on the new block-style archive described in the last post, we now try with categories:

All Categories:

[archives type="monthly" taxonomy="category" sub_options="block" tag="div" sub_ul_class="my_slim_ul" li_class="block_archive_item" limit="10"/]

Single Category

[archives type="monthly" taxonomy="category" term="archive-pro-matic" sub_options="block" tag="div" sub_ul_class="my_slim_ul" li_class="block_archive_item" limit="10"/]

or use the cat attribute:

[archives type="monthly" cat="special1-posts" sub_options="block" tag="div" sub_ul_class="my_slim_ul" li_class="block_archive_item" limit="10"/]

or use the category attribute (alias for cat):

[archives type="monthly" category="special1-posts" sub_options="block" tag="div" sub_ul_class="my_slim_ul" li_class="block_archive_item" limit="10"/]

Multiple Categories

For an archive of multiple categories, the cat_id attribute must be used:

[archives type="monthly" cat_id="55,43" sub_options="block" tag="div" sub_ul_class="my_slim_ul" li_class="block_archive_item" limit="10"/]