WordPress.org

Make WordPress Core

Opened 5 years ago

Last modified 10 months 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 has-patch needs-unit-tests
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 4 years ago.
Quick patch to make this happen
23749.diff (1.2 KB) - added by helen 4 years ago.
23749.2.diff (1.6 KB) - added by helen 4 years ago.

Download all attachments as: .zip

Change History (16)

#2 @nacin
4 years 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.

#3 @helen
4 years ago

  • Keywords good-first-bug added

@danielpataki
4 years ago

Quick patch to make this happen

#4 @danielpataki
4 years 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

#5 @nacin
4 years 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?

#6 @danielpataki
4 years 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

#7 @helen
4 years ago

Still patching, danielpataki?

#8 @danielpataki
4 years 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

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


4 years ago

@helen
4 years ago

@helen
4 years ago

#10 @nacin
4 years 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.

#11 @ipm-frommen
3 years ago

  • Keywords has-patch added

#12 @danielpataki
3 years ago

Wouldn't is_post_format_archive() be clearer in this case?

#13 @swissspidy
10 months ago

  • Keywords needs-unit-tests added
Note: See TracTickets for help on using tickets.