WordPress.org

Make WordPress Core

Opened 14 months ago

Last modified 6 weeks ago

#23749 assigned enhancement

Post Format Archive Conditional Tag

Reported by: danielpataki Owned by: danielpataki
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Post Formats Keywords: good-first-bug
Focuses: template Cc:

Description

As far as I know there is no conditional tag for detecting when a post format archive is shown. I bumped into this problem while creating a theme for quick-blogging and realized that I couldn't create a menu (easily) and style the 'current' post format menu item differently.

I will try and submit a diff if I can although I've never done it before so it may take me a while :)


Attachments (3)

query-mine.patch (1.9 KB) - added by danielpataki 3 months ago.
Quick patch to make this happen
23749.diff (1.2 KB) - added by helen 7 weeks ago.
23749.2.diff (1.6 KB) - added by helen 7 weeks ago.

Download all attachments as: .zip

Change History (13)

comment:2 nacin3 months ago

  • Component changed from Template to Post Formats
  • Focuses template added
  • Milestone changed from Awaiting Review to Future Release

Would be nice to have this.

comment:3 helen3 months ago

  • Keywords good-first-bug added

danielpataki3 months ago

Quick patch to make this happen

comment:4 danielpataki3 months ago

Hi all,

Thanks for giving this some attention! I would love to contribute but it's my first time so I'm quite sure I've got it all wrong. If you could give me some assistance for file naming conventions and so on that would be greatly appreciated.

I pulled the latest version from trunk and made my modifications and generated a diff file. I have tested the code on twentyfourteen using no parameters, a single post format string and post format array. Seems to work fine!

I am worried about one bit though, it seems sloppy. When getting a post format using the get method of $WP_Query a string like this is returned: 'post-format-image' while the query string is simply 'image'. Due to this I used this code:

$post_format = str_replace( 'post-format-', '', $post_format );

It works, but I suspect there is a better way. Apart from this, I basically just copied the way is_post_type_archive works.

Hope I could help, please do let me know how to contribute in a more standard way if I'm doing something wrong!

Daniel

comment:5 nacin3 months ago

  • Milestone changed from Future Release to 3.9
  • Owner set to danielpataki
  • Status changed from new to assigned

Hi Daniel,

Thanks for the patch! This is a good first start. Good idea to model it off is_post_type_archive initially, as that's more or less what I was thinking as well.

In this case, though, we don't need a new query variable. Post type archives are a new construct and didn't have anything existing to represent them. But for a post *format* archive, we have is_tax( 'post-format' ). And to check an individual term, it'd be is_tax( 'post-format', 'post-format-image' ). These are less-than-straightforward (as you note, that term prefix is annoying), hence the desire for a new function.

This new function (and method) just needs to wrap is_tax(), then, optionally accepting a post format name, which then receives the 'post-format-' prefix before being passed to is_tax(). Make sense?

comment:6 danielpataki3 months ago

Hi Andrew,

Ah, yes, I don't know why that didn't occur to me. I think I was a bit blindly copying the established method for the other archive type :) I will revise this patch and post it again. I have since been pointed to the contributing a patch article so I'll use the correct format as well :)

I'll post a patch within the next 24-48 hour, thanks for the help and the attention!

Daniel

comment:7 helen7 weeks ago

Still patching, danielpataki?

comment:8 danielpataki7 weeks ago

Hi helen,

I'm so sorry, I got quite sick for a week right after which must have affected my brain, I completely forgot. I will add this to my list and submit a patch ASAP!

Daniel

comment:9 ircbot7 weeks ago

This ticket was mentioned in IRC in #wordpress-dev by obenland. View the logs.

helen7 weeks ago

helen7 weeks ago

comment:10 nacin6 weeks ago

  • Milestone changed from 3.9 to Future Release

23749.2.diff is fine, but I'm not really feeling it at the moment. is_post_format() would fit the existing pattern, but that's a confusing name. is_post_type_archive() is OK, but it doesn't really fit with other functions (is_category_archive() anyone?). I'm fine with doing this, but let's dwell on it for a bit longer and see if it still makes sense in a month or two.

Note: See TracTickets for help on using tickets.