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" /]

Collapse-Pro-Matic Cookie Based Expand

This is a demo of how to use a cookie to auto-collapse a expand element that is expanded by default. The idea is to set up an expand element this is expanded by default, but if a user collapses it once, it will no longer load auto-expanded for that user until the cookie expires.

For example the following expand element should be auto-expanded until it is manually collapsed. After this, the element will remain collapsed when the page is revisited.

[expand title="test" expanded="once" cookiename="my_cookie"]hidden content[/expand]
test
hidden content

Custom Print Templates for Print-Pro-Matic

Note: This post assumes a basic understanding of WordPress templates and that a child-theme is being used.

To create a custom print template we first need to define a query var to trigger the template.
Add the following to the child-theme’s function.php file:

function printpromatic_query_var( $vars ) {
	$vars[] = 'print_view';
	return $vars;
}
add_filter( 'query_vars', 'printpromatic_query_var' );

Now WordPress will look for something like /?print_view=true at the end of any url.

Next step is to a) define a unique ID for the print trigger and b) tell print-pro-matic to use the current page with the print_view query variable tacked on the url. Do this by setting the url attribute using the %print_view% placeholder as its value:

[print-me id="some_id" url="%print_view%"/]

Finally we need to check for this print_view query var and either a) use a custom print-only template file or b) modify the current page template to switch to a print-only view.

Redirect to Print-Only Template

If a print-only template exists simply redirect to this template file by adding the following code to the child-theme’s function.php file:

function printpro_print_template($original_template) {
    if ( get_query_var( 'print_view' ) ) {
		$new_template = locate_template( array( 'print-template.php' ) );
        return $new_template;
    }
	return $original_template;
}
add_filter( 'template_include', 'printpro_print_template' );

This could be expanded further to support multiple print-only templates based on a value passed to print_view:

[print-me id="monkey_id" url="%print_view=monkey%" title="print monkey"/]
[print-me id="donkey_id" url="%print_view=donkey%" title="print donkey"/]
print monkey
print donkey

This would require that our function be modified to use the correct print template based on the print_view query var:

function printpro_print_template($original_template) {
    $print_view = get_query_var( 'print_view' );
    if ( !empty( $print_view ) ) {
        if($print_view == 'monkey'){
            $new_template = locate_template( array( 'print-template-monkey.php' ) );
        }
        else if ( get_query_var( 'print_view' ) == 'donkey' ){
	    $new_template = locate_template( array( 'print-template-donkey.php' ) );
        }
        if(!empty($new_template)){
            return $new_template;
        }
    }
    return $original_template;
}
add_filter( 'template_include', 'printpro_print_template' );

Modify the Existing Template

This method involves modifying the current page template to change what it displays based on the presence of the print_view query var.

In the page template being used, we need to check if the query_var is present:

$print_view = get_query_var( 'print_view' );

Now we need to simply wrap the existing template elements in an if statement:

//normal
if( empty($print_view) ){
   ...
}
//print only
else{
   ...
}

Collapse-O-Matic CSS Tricks .colomat-close

When an expand element is expanded it has the .colomat-close class assigned. This class is removed when the expand element is collapsed. So, if you want to adjust how an active/expanded trigger is displayed, simply define your custom css as follows:

/*inactive/collapsed */
.collapseomatic {

}

/*active/expanded */
.collapseomatic.colomat-close {

}

Simple Demo

Using the trigclass attribute we can further assign the design of the triggers for only specific expand elements.

CSS

.collapseomatic.my_special_class {
    color: green;
}

.collapseomatic.my_special_class.colomat-close {
    color: red;
    border: 2px dotted red;
}

Shortcode

[expand title="Trigger Text" trigclass="my_special_class"]Hidden Content[/expand]

Result

Trigger Text
Hidden Content

T(-) Countdown w/ T(-) Countdown Events

T(-) Countdown

[tminus t="+40 seconds" style="naboo" event_id="1932" omitweeks="true" launchtarget="countdown"]Launch![/tminus]

Hello world

days
0
0
hours
0
0
minutes
0
0
seconds
4
0

T(-) Countdown Control

[tminus cid="1031" style="naboo" event_id="1932"]

[tminus cid="1031" style="naboo" event_id="1932"]

This is the fireworks div that can be targeted

Collapse-O-Matic Content Filtering

Without Filter Attribute (default off)

Plain Text

[expand title="plain text"]This is just some blibber blabber text[/expand]

plain text
This is just some blibber blabber text

Text with Shortcode

[expand title="text with shortcode"]This is text with a shortcode [tminus_launch_date cid="1921" format="Y-m-d"][/expand]

text with shortcode
This is text with a shortcode [tminus_launch_date cid=”1921″ format=”Y-m-d”]

With Filter Attribute False

Plain Text

[expand title="plain text" filter="false"]This is just some blibber blabber text[/expand]

plain text
This is just some blibber blabber text

Text with Shortcode

[expand title="text with shortcode" filter="false"]This is text with a shortcode [tminus_launch_date cid="1921" format="Y-m-d"][/expand]

text with shortcode
This is text with a shortcode [tminus_launch_date cid=”1921″ format=”Y-m-d”]

With Filter Attribute True

Plain Text

[expand title="plain text" filter="true"]This is just some blibber blabber text[/expand]

plain text

This is just some blibber blabber text

Text with Shortcode

[expand title="text with shortcode" filter="true"]This is text with a shortcode [tminus_launch_date cid="1921" format="Y-m-d"][/expand]

text with shortcode

This is text with a shortcode [tminus_launch_date cid=”1921″ format=”Y-m-d”]