Skip to content

Build an accordion navigation widget

Accordion adds the MD → Accordion Nav widget. It lists the categories of a taxonomy as collapsible sections, each showing its newest posts and a link to the category's archive. You choose the taxonomy, the order, how many categories and posts to show, and whether the current page's category opens.

Before you start

  • You need an Administrator account on a site running Marketers Delight 6.0 or later.
  • Accordion also requires WordPress 6.2 or later and PHP 7.4 or later.
  • Install and activate the Accordion Drop-in.
  • Choose a sidebar or widget area where the navigation should appear.

Add the widget

  1. Go to Appearance → Widgets.
  2. Add MD → Accordion Nav to the widget area you chose.
  3. Open the widget's settings.
  4. Select a Category type to list. The widget uses categories by default; you can choose any public taxonomy, or Auto-detect categories to use the first taxonomy of the post type being viewed.
  5. Enter a Title if the widget needs one.
  6. Select Save in the widget form.
The MD Accordion Nav widget open on Appearance Widgets with Title and Category type visible

Choose which taxonomy the accordion lists.

Choose the categories and posts

These options control which categories appear, in what order, and how much of each one shows.

OptionWhat it controlsDefault
List directionAscending or descending orderAscending
Order byName, Posts count, Slug, Category ID, Category Order, or Latest postName
Posts per categoryHow many posts show inside each category, newest first5
Categories to showHow many top-level categories showEvery category
ExcludeCategory IDs to leave out, separated by commasEmpty

Latest post puts the category with the most recently published post first, so a list of products or topics shows whatever was updated last at the top. With List direction set to Descending, the oldest comes first instead.

When Categories to show cuts the list short, a See all link to the post type's archive follows it, such as "See all 14 changelog categories →". Leave the field empty to show every category.

Show parent categories only leaves child categories out. Otherwise, child categories nest inside their parents. Show post count per category adds a count beside each category.

The Accordion widget options showing Order by, Posts per category, Categories to show and Exclude

Set the order and size of the list.

Open the current page's category

Check Open the current page's category to highlight where the reader is. On a category archive, or on a post in one of the listed categories, that category moves to the top of the list and opens, along with any parent categories. The current post is highlighted inside it.

On pages without a matching category, such as a post type archive or the home page, every section stays closed.

See more text sets the link at the end of each category's posts. {category} and {count} are available in this field. When the field is empty, the link reads "See more in {category} →". CSS classes adds classes to the accordion wrapper.

Only show posts that share the page's limits the accordion to posts that have the same category as the current page in a second taxonomy. For example, a product page in a "Stream" product category can list only the docs filed under that same product, grouped by their docs categories.

  1. In Category type, select the taxonomy to group by, such as your docs categories.
  2. In Only show posts that share the page's, select the taxonomy the page and the posts have in common.
  3. Select Save.
The Only show posts that share the page's setting with a taxonomy selected

List only posts that share the page's category.

When this setting is on:

  • Every matching post shows in its category, and there is no See more link, because the category's archive would also show unrelated posts.
  • If only one category has matching posts, it opens automatically.
  • On a page that has no category in that taxonomy, the widget doesn't show.

Check the result

Open a page where the widget area appears. You should see category sections that expand to show their newest posts. If you set Categories to show, a See all link follows the list when there are more.

The widget shows nothing at all, title included, when no category has posts to list. If it is missing, check that it's in the intended widget area, then check Category type, Exclude and Only show posts that share the page's. If you use a caching plugin, clear its cache and reload.

Alex Mangini

Hi, I'm Alex! I started writing about web design and blogging at 13 years old, which turned into client work, which led to building my own software. 15 years later I'm still at it, and Marketers Delight is the epitome of my philosophy for building on the web.