Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to isolate a particular post format for images, and reading the Codex, I thought it would be possible to create a new template file single-image.php. However, that file is not being used. Instead, I've got a file called content-image.php instead.

I've refreshed permalinks, still no joy.

Here's register_post_type():

function register_post_type( $post_type, $args = array() ) {
global $wp_post_types, $wp_rewrite, $wp;

if ( !is_array($wp_post_types) )
    $wp_post_types = array();

// Args prefixed with an underscore are reserved for internal use.
$defaults = array(
    'labels' => array(), 'description' => '', 'publicly_queryable' => null, 'exclude_from_search' => null,
    'capability_type' => 'post', 'capabilities' => array(), 'map_meta_cap' => null,
    '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'hierarchical' => false,
    'public' => false, 'rewrite' => true, 'has_archive' => false, 'query_var' => true,
    'supports' => array(), 'register_meta_box_cb' => null,
    'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null,
    'can_export' => true,
    'show_in_nav_menus' => null, 'show_in_menu' => null, 'show_in_admin_bar' => null,
    'delete_with_user' => null,
);
$args = wp_parse_args($args, $defaults);
$args = (object) $args;

$post_type = sanitize_key($post_type);
$args->name = $post_type;

if ( strlen( $post_type ) > 20 )
        return new WP_Error( 'post_type_too_long', __( 'Post types cannot exceed 20 characters in length' ) );

// If not set, default to the setting for public.
if ( null === $args->publicly_queryable )
    $args->publicly_queryable = $args->public;

// If not set, default to the setting for public.
if ( null === $args->show_ui )
    $args->show_ui = $args->public;

// If not set, default to the setting for show_ui.
if ( null === $args->show_in_menu || ! $args->show_ui )
    $args->show_in_menu = $args->show_ui;

// If not set, default to the whether the full UI is shown.
if ( null === $args->show_in_admin_bar )
    $args->show_in_admin_bar = true === $args->show_in_menu;

// Whether to show this type in nav-menus.php. Defaults to the setting for public.
if ( null === $args->show_in_nav_menus )
    $args->show_in_nav_menus = $args->public;

// If not set, default to true if not public, false if public.
if ( null === $args->exclude_from_search )
    $args->exclude_from_search = !$args->public;

// Back compat with quirky handling in version 3.0. #14122
if ( empty( $args->capabilities ) && null === $args->map_meta_cap && in_array( $args->capability_type, array( 'post', 'page' ) ) )
    $args->map_meta_cap = true;

if ( null === $args->map_meta_cap )
    $args->map_meta_cap = false;

$args->cap = get_post_type_capabilities( $args );
unset($args->capabilities);

if ( is_array( $args->capability_type ) )
    $args->capability_type = $args->capability_type[0];

if ( ! empty($args->supports) ) {
    add_post_type_support($post_type, $args->supports);
    unset($args->supports);
} elseif ( false !== $args->supports ) {
    // Add default features
    add_post_type_support($post_type, array('title', 'editor'));
}

if ( false !== $args->query_var && !empty($wp) ) {
    if ( true === $args->query_var )
        $args->query_var = $post_type;
    else
        $args->query_var = sanitize_title_with_dashes($args->query_var);
    $wp->add_query_var($args->query_var);
}

if ( false !== $args->rewrite && ( is_admin() || '' != get_option('permalink_structure') ) ) {
    if ( ! is_array( $args->rewrite ) )
        $args->rewrite = array();
    if ( empty( $args->rewrite['slug'] ) )
        $args->rewrite['slug'] = $post_type;
    if ( ! isset( $args->rewrite['with_front'] ) )
        $args->rewrite['with_front'] = true;
    if ( ! isset( $args->rewrite['pages'] ) )
        $args->rewrite['pages'] = true;
    if ( ! isset( $args->rewrite['feeds'] ) || ! $args->has_archive )
        $args->rewrite['feeds'] = (bool) $args->has_archive;
    if ( ! isset( $args->rewrite['ep_mask'] ) ) {
        if ( isset( $args->permalink_epmask ) )
            $args->rewrite['ep_mask'] = $args->permalink_epmask;
        else
            $args->rewrite['ep_mask'] = EP_PERMALINK;
    }

    if ( $args->hierarchical )
        add_rewrite_tag("%$post_type%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name=");
    else
        add_rewrite_tag("%$post_type%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name=");

    if ( $args->has_archive ) {
        $archive_slug = $args->has_archive === true ? $args->rewrite['slug'] : $args->has_archive;
        if ( $args->rewrite['with_front'] )
            $archive_slug = substr( $wp_rewrite->front, 1 ) . $archive_slug;
        else
            $archive_slug = $wp_rewrite->root . $archive_slug;

        add_rewrite_rule( "{$archive_slug}/?$", "index.php?post_type=$post_type", 'top' );
        if ( $args->rewrite['feeds'] && $wp_rewrite->feeds ) {
            $feeds = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')';
            add_rewrite_rule( "{$archive_slug}/feed/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' );
            add_rewrite_rule( "{$archive_slug}/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' );
        }
        if ( $args->rewrite['pages'] )
            add_rewrite_rule( "{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type=$post_type" . '&paged=$matches[1]', 'top' );
    }

    add_permastruct( $post_type, "{$args->rewrite['slug']}/%$post_type%", $args->rewrite );
}

if ( $args->register_meta_box_cb )
    add_action('add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1);

$args->labels = get_post_type_labels( $args );
$args->label = $args->labels->name;

$wp_post_types[$post_type] = $args;

add_action( 'future_' . $post_type, '_future_post_hook', 5, 2 );

foreach ( $args->taxonomies as $taxonomy ) {
    register_taxonomy_for_object_type( $taxonomy, $post_type );
}

do_action( 'registered_post_type', $post_type, $args );

return $args;

}

share|improve this question

1 Answer 1

Are you trying to style the page for the image or what the image looks like embedded within a post? If you're trying to style the page for the image, you want to use image.php or attachment.php if you want a global style for all attachments

share|improve this answer
    
I'm actually trying to wrap the image in a custom tag, and wrap that custom tagged image in some other custom divs. The post-type is image (post format, post type whatever). The post will only contain a title and an image. –  Jon Mitten Aug 8 '13 at 21:39
    
single-image.php should work, can you copy+paste your register_post_type() function? –  George Yates Aug 8 '13 at 23:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.