custom url – add attachment’s id or name after post

Showing links to attachments in the desired format

Loop through the attachments and generate the link you want:

$args = array(
    'post_type' => 'attachment',
    'numberposts' => null,
    'post_status' => null,
    'post_parent' => $post->ID
);
$attachments = get_posts($args);
if ($attachments) {
    foreach ($attachments as $attachment) {
        echo '<a href="' . get_permalink() . 'video/' . $attachment->ID . '">' . apply_filters('the_title', $attachment->post_title) . '</a>';
    }
}

Getting the video variable and using single.php

Sorry it took me a while, there’s a very simple way to do this in WordPress using url endpoints.

Paste the following code inside your functions.php:

add_action( 'init', 'video_endpoint' );
function video_endpoint() {
    add_rewrite_endpoint( 'video', EP_PAGES | EP_PERMALINK );
}

Make sure you refresh your permalinks by going to the admin permalinks page and hitting ‘save changes’.

Once you’ve done that you can access the video parameter in your templates using:

echo get_query_var( 'video' );

NOTE:
Above where you see EP_PAGES this is the scope of where the endpoint will work. Some possible values are EP_ALL, EP_ROOT, EP_PERMALINK, EP_CATEGORIES, EP_TAGS and so on.