Opened 12 years ago
Last modified 4 years 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 has-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)
Change History (18)
#2
@
11 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.
#4
@
11 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
@
11 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
@
11 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
#8
@
11 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.
11 years ago
#10
@
11 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.
This ticket was mentioned in Slack in #core by sergey. View the logs.
5 years ago
This ticket was mentioned in PR #362 on WordPress/wordpress-develop by deepaklalwani97.
4 years ago
#15
- Keywords has-unit-tests added; needs-unit-tests removed
Refreshes the patch and add unit test cases
Trac ticket: https://core.trac.wordpress.org/ticket/23749
See http://codex.wordpress.org/Function_Reference/is_tax#Post_Formats.