Opened 10 years ago
Closed 10 years ago
#33860 closed enhancement (wontfix)
Loop helpers function
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | |
| Component: | Query | Keywords: | has-patch has-unit-tests |
| Focuses: | template | Cc: |
Description
while(have_post()) {
the_post();
if(is_loop_first()){
echo 'first';
}
if(is_loop_index(5)){
echo 'is 5 index element';
}
if(is_loop_last()){
echo 'last';
}
}
Attachments (3)
Change History (13)
#3
@
10 years ago
- Keywords has-unit-tests added; needs-unit-tests removed
33860.diff adds three helper functions: query_post_index(), query_is_first_post() and query_is_last_post(). Including tests.
Getting the first and last post is usually needed more often, as odd/even queries are usually used for styling only (which you can target with CSS). If you want to detect the odd/even post, you can create your own helper function leveraging query_post_index().
#4
@
10 years ago
33860.2.diff is an updated patch after the recent changes to the factory properties.
#5
@
10 years ago
I'm not convinced we really need these. It doesn't feel like we're gaining a lot by them for the cost of having to maintain them going forward.
#7
@
10 years ago
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to closed
I'm not convinced we really need these. It doesn't feel like we're gaining a lot by them for the cost of having to maintain them going forward.
It's easy to implement this on your own if you wish, but I think for now this is not something we should do.
#8
@
10 years ago
- Keywords close removed
- Resolution wontfix deleted
- Status changed from closed to reopened
I think that this is good idea to add this to core. This is interesting helper
#10
@
10 years ago
- Keywords 2nd-opinion good-first-bug removed
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from reopened to closed
- Version 4.3 deleted
I feel like it being a good idea, or interesting, is still not a good enough reason to add these.
The original proposition hasn't changed since this ticket was closed. There should be a Core need to adopt these functions, which is currently not there.
In the past I've had the need to determine first/last/odd/even posts in the loop.
I think these functions need better names, and we'll need to decide whether first/last means the first/last in the current loop or the first/last in the current loop's query. Might be worth taking a look at some theme frameworks to see if there's prior art.
These will of course need unit tests.