changing permalink for custom template in posts of a certain category

I’ve created a unique single post template to give people the option of reading all posts of a certain category using the awesome “reveal.js” which they access via this link

<a href="?show=presentation/">presentation</a>

The problem is the ugly URLs, which end up looking like

Read More
website.com/post-name/?show=presentation
website.com/completely-different-post-name/?show=presentation

I would like them to look like

website.com/post-name/presentation/
website.com/completely-different-post-name/presentation/

I’ve spent the last 10 or so hours trying to figure this out (I haven’t even gone to sleep yet, lol); unfortunately, nothing has worked.

Is there a way to do this?

As a side note, the site I’m trying to do this on is installed in a subdirectory (localhost/wp) but I’m developing this for my actual website which is installed in a top level directory

Related posts

Leave a Reply

1 comment

  1. You can achieve this via the Rewrite API‘s add_rewrite_endpoint:

    function wpa89344_add_presentation_endpoint(){
        add_rewrite_endpoint( 'presentation', EP_PERMALINK );
    }
    add_action('init', 'wpa89344_add_presentation_endpoint');
    

    Then in your template or wherever you differentiate a presentation vs normal view, check the global $wp_query for the presence of the presentation query var:

    global $wp_query;
    if( isset( $wp_query->query_vars['presentation'] ) ){
        include(TEMPLATEPATH . "/single_wide_report.php");
    } else {
        include(TEMPLATEPATH . "/single_normal_report.php");
    }
    

    Note that you need to visit the permalinks settings page after adding the endpoint to flush permalinks and create the new rewrite rules.

    EDIT- Output of $wp_query in single.php:

    enter image description here