Test if a Category contains certain Custom Post Types

1) “need ascending chronological order on Category archive pages, but only if they contain one or more posts from my specified Custom Post Types”

I don’t think this is possible; at least not practical. However, since posting the question I’ve setup custom taxonomies for my Custom Post Types which negates the need for this. The Custom Post Type archive pages are already sorted the way I want so since the Categories no longer contain Custom Post Types, their sorting can be handled by a simple Category sorting plugin.


2) “default pagination is labeled incorrectly. i.e., the oldest post is on the top of the first page and when I scroll to the bottom, the link is labeled ‘Older posts’ but this link really takes you to the newer posts.”

This is handled by the theme and quite goofy IMO. See notes below*.

Twenty Thirteen uses the twentythirteen_paging_nav() function (contained in functions.php) to setup these pagination links…

function twentythirteen_paging_nav() {
    global $wp_query;

    // Don't print empty markup if there's only one page.
    if ( $wp_query->max_num_pages < 2 )
        return;
    ?>
    <nav class="navigation paging-navigation" role="navigation">
        <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentythirteen' ); ?></h1>
        <div class="nav-links">

            <?php if ( get_next_posts_link() ) : ?>
            <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentythirteen' ) ); ?></div>
            <?php endif; ?>

            <?php if ( get_previous_posts_link() ) : ?>
            <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentythirteen' ) ); ?></div>
            <?php endif; ?>

        </div><!-- .nav-links -->
    </nav><!-- .navigation -->
    <?php
}

Look very carefully at the code above and ignore the “older/newer” labels. Within the conditional logic for the “next” link, you have the next_posts_link() function wrapped inside HTML that is labeled nav-previous. Vice-versa for the other link… the previous_posts_link() function wrapped inside nav-next. Like I said before… goofy.

My fix was simple. I copied this entire function into my child theme’s functions.php file. Since the original is wrapped inside if ( ! function_exists( 'twentythirteen_paging_nav' ) ), the copy in the child theme will take precedence. Then I rearranged the function so that the next_posts_link() appears inside the .nav-next div and re-labeled to "Next page", and did the same for the previous_posts_link() function.

function twentythirteen_paging_nav() {
    global $wp_query;

    // Don't print empty markup if there's only one page.
    if ( $wp_query->max_num_pages < 2 )
        return;
    ?>
    <nav class="navigation paging-navigation" role="navigation">
        <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentythirteen' ); ?></h1>
        <div class="nav-links">

            <?php if ( get_next_posts_link() ) : ?>
                  <div class="nav-next">
                     <?php next_posts_link( __( 'Next page <span class="meta-nav">&rarr;</span>', 'twentythirteen' ) ); ?>
                 </div>
            <?php endif; ?>

            <?php if ( get_previous_posts_link() ) : ?>
                <div class="nav-previous">
                    <?php previous_posts_link( __( '<span class="meta-nav">&larr;</span> Previous page', 'twentythirteen' ) ); ?>
                </div>
            <?php endif; ?>

        </div><!-- .nav-links -->
    </nav><!-- .navigation -->
    <?php
}

The final step is to tweak the CSS as Twenty Thirteen makes the “previous” link in the lower-left corner (formally called “Older posts”) about 60% larger than other. I think their idea was to make the button going to the “next” page larger. Since the positions and labels are flipped, you must adjust the CSS sizes.


*Notes: In the context of the newest post being on top, the “next” page would be “older” posts. In this theme, the link to the “next” page is labeled “older posts” and it’s pointing to the left signifying “back”. I call it “goofy” because it will totally break down when posts are sorted in any other fashion. When oldest posts are on top, when they’re sorted alphabetically, etc., the “older” label is rendered meaningless. Since it, technically, goes to the next page of the results query, it should be labeled “next” and indeed the next_posts_link() function is how it’s created. However, simply re-labeling it as “next” is not good enough as it’s in the lower-left corner and pointing backwards towards the left. Wrapping it with the appropriate CSS class nav-next fixes this as described in my answer above.