“post-format” code snippets list [closed]

Using get_template_part() with Post Formats This is a really handy little snippet to use when you want to change the output format for each post format. if ( have_posts() ) : while ( have_posts() ) : the_post(); // Standard is the default template for posts with no post format // As the formats doesn’t contain … Read more

About post format

Post formats are not magic. Your theme needs to actually have a code to generate different HTML (or apply different CSS rules) for different format. Having the theme “suuport” post formats is nice for future compatibility of the content, but by itself it doesn’t do anything to how the content is displayed.

Adding new post format on plugin activation

Unlike the other taxonomies, you cannot use wp_inset_term() to add terms to the post_format taxonomy as you cannot add new terms to this taxonomy. You need to add the terms for the post_format via add_theme_support(), something like add_theme_support( ‘post-formats’, array( ‘aside’, ‘gallery’ ) );

If post-format == ‘gallery’ conditional

This one’s an easy fix! The first argument in has_post_format() is a string in the format post-format-{type}, e.g. post-format-aside, or post-format-gallery, etc. So, e.g., change this: has_post_format( ‘aside’ , $post_id ) To this: has_post_format( ‘post-format-aside’ , $post_id ) Wash, rinse, and repeat for all uses of has_post_format(). EDIT Given your example code, I would even … Read more

Formatting Standard Post Format

Technically speaking, there is no “standard” Post Format. Rather, “standard” is simply the default – as in, no Post Format type is defined. If no Post Format type is defined, get_post_format() simply returns null. I would suggest re-factoring your code above, and re-naming your icon images using the exact Post Format string. That way, you … Read more