WordPress.org

Make WordPress Core

Opened 7 years ago

Last modified 2 months ago

#4969 new enhancement

Make wp_list_* functions all behave similarly...

Reported by: pishmishy Owned by: ryan
Milestone: Future Release Priority: normal
Severity: normal Version: 2.3
Component: Themes Keywords: has-patch accessibility lists
Focuses: template Cc:

Description

The sidebar template typically uses lists of lists to prettily display lists of pages, categories and bookmarks. Lists of pages, categories and bookmarks are forced to be items of lists themselves as the functions wp_list_pages(),wp_list_categories() and wp_list_bookmarks() wrap the output of functions in <li>..</li> tags by default.

Lists are intended to indicate something about the structure of the document where as these forced <li> tags appear to be intended to provide pretty indentation. Nested-lists can also provide confusion for non-visual readers.

wp_list_bookmarks() provides the ability to override this with category_before and category_after options. wp_list_pages() and wp_list_categories() should offer similar options. Ideally the accessible approach would be the default for these options but I don't believe this is possible without breaking existing themes.

Attachments (4)

4969-list-cats.diff (1.1 KB) - added by Otto42 7 years ago.
Patch for wp_list_categories
4969-list-pages.diff (1.2 KB) - added by Otto42 7 years ago.
Patch for wp_list_pages
4969.patch (1.9 KB) - added by pishmishy 6 years ago.
Revised patch
4969.diff (969 bytes) - added by wojtek.szkutnik 4 years ago.

Download all attachments as: .zip

Change History (24)

comment:1 follow-up: pishmishy7 years ago

  • Keywords has-patch lists added
  • Owner changed from anonymous to pishmishy
  • Severity changed from trivial to normal
  • Status changed from new to assigned

Added patch. I'm not sure why the options are called category_before, category_after. I suspect they need to be changed to something more descriptive but I've continued the pattern for now.

comment:2 in reply to: ↑ description ; follow-up: Otto427 years ago

Replying to pishmishy:

The sidebar template typically uses lists of lists to prettily display lists of pages, categories and bookmarks. Lists of pages, categories and bookmarks are forced to be items of lists themselves as the functions wp_list_pages(),wp_list_categories() and wp_list_bookmarks() wrap the output of functions in <li>..</li> tags by default.

Lists are intended to indicate something about the structure of the document where as these forced <li> tags appear to be intended to provide pretty indentation. Nested-lists can also provide confusion for non-visual readers.

The purpose of these lists is not for indentation, it's for document structure.

Generally speaking, the entire sidebar can be considered one big list of items. Each "item" is a whole sidebar entry. This is a perfectly acceptable structure, you have a big list of entries. The fact that each entry is large vertically does not make the unordered list structure incorrect. And indentation is not a factor here either, generally speaking, as the entire sidebar is styled to a specific position.

Now, the individual elements of that sidebar might contain list information themselves, such as a list of pages or list of bookmarks or what have you. But the content of that sidebar list item is irrelevant, it can be anything desired.

wp_list_bookmarks() provides the ability to override this with category_before and category_after options.

wp_list_bookmarks is a special case, as it generates *multiple* list items intended for inclusion into a sidebar. By default, each category becomes a separate sidebar entry, instead of the entire unit being one sidebar entry with multiple subentries.

Because of this multiple nature, it needs these extra before and after options because not all themes use lists for the entire sidebar. I've seen sidebars that use nested divs, for example. These themes would have a div around each sidebar section, and so the wp_list_bookmarks would need to know those div elements in order to wrap each one in a div instead of a list.

wp_list_pages() and wp_list_categories() should offer similar options.

wp_list_pages and wp_list_categories do not actually generate multiple sidebar, and so they do not need these similar options.

Recommend closing this as wontfix.

comment:3 in reply to: ↑ 1 Otto427 years ago

Replying to pishmishy:

Added patch. I'm not sure why the options are called category_before, category_after. I suspect they need to be changed to something more descriptive but I've continued the pattern for now.

wp_list_bookmarks() uses category before and after because it's wrapping each category in a separate sidebar entry. Use of this pattern in these other functions is incorrect, even if it was necessary.

comment:4 Otto427 years ago

On the other hand, looking closer, I do see your point to some degree. As far as consistency goes, it would make a lot more sense if the pages and categories functions had title_before and after as well as a normal before and after wrapping the whole thing. The style == 'list' is being misused in the categories, for example.

Here's a patch for wp_list_categories that I think is more consistent overall.

Otto427 years ago

Patch for wp_list_categories

Otto427 years ago

Patch for wp_list_pages

comment:5 Otto427 years ago

  • Summary changed from Lists within lists to Make wp_list_* functions all behave similarly...

wp_list_pages is trickier, it doesn't make much sense to not have it in an unordered list internal to the sidebar item, since it's hierarchical in nature. So it was strangely overriding the existence of a title_li to make it not display the UL even though it had no way to not display the LIs around each entry.

Patch attached to make it more consistent with the others.

comment:6 in reply to: ↑ 2 ; follow-up: pishmishy7 years ago

Replying to Otto42:

The purpose of these lists is not for indentation, it's for document structure.

Generally speaking, the entire sidebar can be considered one big list of items.

That's fine if it's what you're after (and I admit for most people it is), but it'd be nice if a theme author could have option of not using a list of lists if they so desire. Allow consistant unwrapping of the <li> tags if desired doesn't come at any cost.

Many thanks for your work on further patches for this ticket.

comment:7 in reply to: ↑ 6 ; follow-up: Otto427 years ago

Replying to pishmishy:

That's fine if it's what you're after (and I admit for most people it is), but it'd be nice if a theme author could have option of not using a list of lists if they so desire.

I don't understand your objection, theme authors do have that option. Many themes use divs instead, for example. All the bits in there where it generates lists for sidebar items can be overriden with arguments.

comment:8 pishmishy6 years ago

  • Keywords needs-testing added

I haven't looked at this ticket in a while. I'm still convinced that we should be able to use _before and _after arguments with this function.

comment:9 pishmishy6 years ago

  • Milestone changed from 2.5 to 2.6

Bumping milestone for feature freeze.

comment:10 in reply to: ↑ 7 vlogtheimpaler6 years ago

Replying to Otto42:

Replying to pishmishy:

That's fine if it's what you're after (and I admit for most people it is), but it'd be nice if a theme author could have option of not using a list of lists if they so desire.

I don't understand your objection, theme authors do have that option. Many themes use divs instead, for example. All the bits in there where it generates lists for sidebar items can be overriden with arguments.

I believe the objection presented there is allowing theme authors to be able to retain categorization while broken out of list mode. While currently it's possible to replace the tags for list items, the unordered list element is still present when categorization is enabled. Meaning if you want to keep categories but drop lists, in it's current form it's a bit inflexible to do so.

A bug also worth mentioning, is while attempting to pass double quotes as part of your string in either the before or after portions for tags that write lists. Like wp_list_bookmarks and possibly other tags, the output is passed but the quotes become escaped instead of switched or stripped completely. I understand why this happens, I'm just not sure whether or not double quotes should actually be passed if user wishes to pass a class variable for their custom before or after arguments.

comment:11 pishmishy6 years ago

I've also noticed that wp_list_pages(),wp_list_bookmarks(), wp_list_categories() have a title_li argument, but wp_get_archives needs to be wrapped as:

<li><h2>Archives</h2>
    <ul>
        <?php wp_get_archives('type=monthly'); ?>
    </ul>
</li>

Can I also make an argument for the functions to be consistent in this fashion?

pishmishy6 years ago

Revised patch

comment:12 pishmishy6 years ago

Fresh patch, fixing the issues mentioned above, with no impact forseen on existing themes. Allows before/after on wp_list_pages() and wp_list_categories().

comment:13 ryan6 years ago

  • Owner changed from pishmishy to ryan
  • Status changed from assigned to new

comment:14 Denis-de-Bernardy5 years ago

there are several dups of this one

comment:15 Denis-de-Bernardy5 years ago

  • Component changed from General to Template

comment:16 Denis-de-Bernardy5 years ago

  • Keywords needs-patch added; has-patch needs-testing removed
  • Milestone changed from 2.9 to Future Release

wojtek.szkutnik4 years ago

comment:17 wojtek.szkutnik4 years ago

  • Cc wojtek.szkutnik@… added
  • Keywords has-patch gsoc added

Apart from the after/before discussion, the archive title thing can be fixed.

comment:18 bpetty20 months ago

  • Keywords needs-patch gsoc removed

comment:19 johnbillion3 months ago

#3567 was marked as a duplicate.

comment:20 nacin2 months ago

  • Component changed from Template to Themes
  • Focuses template added
Note: See TracTickets for help on using tickets.