• Resolved rubai

    (@rubai)


    I’m totally new to WordPress theme-ing and am having some problems understanding the concept of post formats. I was wondering how to style different post format and how to keep each format in its own file so it’s manageable. I read a article on:
    http://dougal.gunters.org/blog/2010/12/10/smarter-post-formats/
    but did not get anything. How can I style different post formats and keep them each in a separate file?
    -Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Do you want to style them differently (i.e. CSS), or do you want to have a different markup/layout for each one (i.e. HTML)?

    Thread Starter rubai

    (@rubai)

    Both I guess. For example- a video post will have a video icon next to the title and will concentrate most on showcasing the video. I know how to do it using if/else in my loop but is there most manageable way to do it? like keep each different style in a defferent file (post-video.php,post-standard.php).

    Both I guess. For example- a video post will have a video icon next to the title and will concentrate most on showcasing the video.

    For CSS differentiation, ensure that you use the post_class() template tag, which will enable you to take advantage of the post-format specific CSS classes that WordPress generates for the post container – such as .format-video or .format-gallery.

    For even more CSS control, ensure that you use the body_class() template tag, which will enable you to take advantage of the post-format specific CSS classes that WordPress generates for the HTML body tag – such as .single-format-video or .single-format-gallery. for single blog post pages, and .term-post-format-video and .term-post-format-gallery for taxonomy archive index pages.

    I know how to do it using if/else in my loop but is there most manageable way to do it? like keep each different style in a defferent file (post-video.php,post-standard.php).

    Now the real fun begins! One of the tricks of the trade is the quite handy get_post_format() template tag, which you can use like so:

    get_template_part( 'post', get_post_format() );

    Which will get post-video.php or post-gallery.php, etc. Using this method will completely eliminate the need to use a bunch of if/else statements, or a switch, etc.

    Note that get_post_format() returns FALSE if no post format is set (i.e. for standard post format), so you can either have a post.php as a fallback, or you can use an approach such as this one:

    $post_format = ( get_post_format() ? get_post_format() : 'standard' );

    …which will then cause this:

    get_template_part( 'post', $post_format );

    …to get post-standard.php for “standard” post formats.

    Thread Starter rubai

    (@rubai)

    Ok, got it. Thnaks a lot!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Post Formats, get_template_part & styling problems’ is closed to new replies.