[wp-hackers] get_theme_support( 'post-formats' )

Chip Bennett chip at chipbennett.net
Wed Jan 12 16:32:52 UTC 2011


Does this preclude the need to bother with get_theme_support()? Or will I
generate errors for unsupported $format->name values?

Chip

On Wed, Jan 12, 2011 at 10:22 AM, Otto <otto at ottodestruct.com> wrote:

> Simpler:
>
> $formats = get_terms('post_format');
> foreach ($formats as $format) {
> echo $format->name;
> echo $format->count;
> }
>
> -Otto
>
>
>
> On Wed, Jan 12, 2011 at 11:08 AM, Chip Bennett <chip at chipbennett.net>
> wrote:
> > Or can I just use
> > get_categories()<
> http://codex.wordpress.org/Function_Reference/get_categories>
>  > ?
> >
> > $postformatobj = get_categories( 'taxonomy' => 'post-formats' );
> > $postformatcount = $postformatobj->count;
> >
> > Any reason why that wouldn't work?
> >
> > Chip
> >
> >
> > On Wed, Jan 12, 2011 at 10:02 AM, Chip Bennett <chip at chipbennett.net>
> wrote:
> >
> >
> >
> >> As a follow-up question: if I want to retreive the count of each Post
> >> Format type, what would be the best approach?
> >>
> >> Perhaps something like (used inside a foreach, where $postformat is the
> >> slug):
> >>
> >> $postformatobj = get_term_by( slug, $postformat, 'post-formats' );
> >>
> >> $postformatcount = $postformatobj->count;
> >>
> >> Would that work? is there a better way?
> >>
> >> Thanks again,
> >>
> >> Chip
> >>
> >>
> >>   On Wed, Jan 12, 2011 at 9:38 AM, Chip Bennett <chip at chipbennett.net
> >wrote:
> >>
> >>
> >>> That's exactly what I was curious about. Thanks for clarifying, Otto!
> >>>
> >>> Chip
> >>>
> >>>
> >>>   On Wed, Jan 12, 2011 at 9:34 AM, Otto <otto at ottodestruct.com> wrote:
> >>>
> >>>
> >>>> On Wed, Jan 12, 2011 at 8:57 AM, Chip Bennett <chip at chipbennett.net>
> >>>> wrote:
> >>>> > $my_theme_supports = get_theme_support( 'post-formats' );
> >>>> > ...should result in, e.g.
> >>>> > $my_theme_supports = array( 'aside', 'gallery' );
> >>>>
> >>>>
> >>>> Actually, it returns an array with an array in it.
> >>>>
> >>>> array(1) { [0]=> array(9) {
> >>>> [0]=> string(5) "aside" [1]=> string(5) "audio" ...
> >>>> } }
> >>>>
> >>>> So you'll want to reference it with the [0].
> >>>>
> >>>> Simple code:
> >>>>
> >>>> $my_theme_supports = get_theme_support( 'post-formats' );
> >>>>
> >>>> if (is_array($my_theme_supports)) $my_theme_supports =
> >>>> $my_theme_supports[0];
> >>>>
> >>>> Now you'll have what you expect it to be.
> >>>>
> >>>> -Otto
> >>>> _______________________________________________
> >>>> wp-hackers mailing list
> >>>> wp-hackers at lists.automattic.com
> >>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
> >>>>
> >>>
> >>>
> >>
> >>
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list