Support » Fixing WordPress » Separating Display of Post with image from Post without Image

  • Hi Guys,

    Can anyone help me with the following?

    I have two types of post:
    1. With Image (attachment.php)
    2. Without Image (single-post.php)

    I’ve been trying to find a way to separate how these posts will be displayed.

    I tried looking at the hierarchy. Since my posts types are single-post.php and those with attachment.php, I modified the two of the to display different layout in their individual post. I did not modify the single.php.

    However it seems that the format they are following is the single-post.php and the attachement.php (the one with image) is being bypassed.

    Can any one point me to the right direction?

    Thanks in advance!

Viewing 1 replies (of 1 total)
  • Hello Aidorm,

    First, a ‘post type’ has a specific meaning in WordPress: ‘page’, ‘post’, ‘attachment’, ‘links’ are all different post types, and of course, you can define your own custom post types.

    It appears to me you’re only talking about ‘posts’ post type (yeah, I know: very confusing — let’s just call it blog posts), and you want a way to style groups of individual blog posts differently.

    Attachment.php is used to display attachments (ie the individual media files attached to the blog post), and not the blog post itself.

    What you want to achieve doesn’t exist out of the box, and you’ll need to either add some code in your functions.php to define the template file, or use a plugin.

    If you want the ability to set the template for individual posts, use Single Post Template plugin.

    Alternatively, you could create two (or more) categories and use the (untested) code below in your theme’s functions.php file to define category-specific single post template files:

    Ref: http://mor10.com/creating-custom-single-post-templates/

    add_filter('single_post_template', create_function(
    	'$the_template',
    	'foreach( (array) get_the_category() as $cat ) {
    		if ( file_exists(TEMPLATEPATH . "/single-{$cat->slug}.php") )
    		return TEMPLATEPATH . "/single-{$cat->slug}.php"; }
    	return $the_template;' )
    );

    Name your template files single-catslug.php (where catslug is the slug of your category, and this template file *should* be used to display all individual posts in this category.

Viewing 1 replies (of 1 total)
  • The topic ‘Separating Display of Post with image from Post without Image’ is closed to new replies.