Display Categories with Loopers

Heya!

Two parts to this topic’s question:

  1. How do I use categories in general as a looper provider? (Imagine a grid-based category navigation gallery)
  2. How do I target specific categories to display (Display these arbitrary 8 categories out of 10 total)

It’s easy to pull posts WITHIN a category using existing tools of course, but I’m not sure which looper provider type is the best tool for these top-level items… and if I’m being honest I don’t even know what string to use. :stuck_out_tongue:

Hi @Rule72,

Thanks for reaching out.
It is not very clear what exactly you are trying to do here. If you are trying to show the categories while showing the Post you can use the {{dc::term:name}}. If you want to show the posts from specific categories you can use the Query Builder from Looper Provider and specify the categories in the Taxonomies option which you want to show.

Screenshot-2022-04-05-174801

If you want to show only the Categories, you can use the All the Terms from Looper Provider. But there is no option to show specific categories only.

Screenshot-2022-04-05-174841

If that is not the case, please explain it a bit more for further assistance.

Thanks

The second item is what I wanted to achieve, however I only wanted to display arbitrary categories (rather than all of them).

If what you are saying is entirely right, there is no way to do that with the default looper provider… so, a workaround is that I can add custom meta (via ACF) to the specific categories’ pages and then target that with the looper—this sounds like solid logic to you too, right?

Hello @Rule72,

You can use the Looper Provider Custom and create your own custom code that will return only the 8 categories that you want to display. Perhaps this old thread can help:

And also, this video might be of interest to you:

Best Regards.

1 Like

Dope, thanks!

I TRY to avoid php for these more simple types of layout / display implementation things when possible, if a plugin/native solution is faster (easier to explain to clients, easier for me to map out and visualize), but the resources above solve that need if it turns out I can’t find something else.

The other question I can find being useful here is this:

ACF Targeting

Using a dc string… is there an easy way to target specific values set for an ACF field (checkbox), or is it simply best to stick with single-value options (radio)? ( Link to ACF string article for completeness )

image

I’m unfamiliar with how targeting the field PLUS a specific value might work in context.

Hey @Rule72,

It would be easier to use single-value radios. If you use a checkbox, you need to loop through the values and set up conditions.

If you haven’t done so yet, I’d recommend you go through the series of tutorials to learn more about the combined usage of ACF Pro and Loopers here https://youtu.be/7w7nD6W9tlk

Hope that helps.

1 Like

Nice! That’s most of the missing piece of context I needed here. Thanks!

You’re welcome, @Rule72.

I’m still having trouble wrapping my head around this:

  • Have the looper provider target any items that have a particular ACF field added (in this case, all post categories)
  • Only pull items which have a specific value in that specific field.

I thought this was the way to go, is this inaccurate:
image

I watched through the video asset above, but I think the problem is sourced from me working outside typica post metadata (eliminating the post_field option I believe) by working on categories themselves.

Hey @Rule72,

We’re not quite sure about your issue, would you mind sharing more information? or what’s your goal? It would also be best if you could share with us your admin credentials so that we can properly check them. To do that, please give us the following information in a Secure Note.

  • WordPress Login URL
  • Admin level username and password

You can find the Secure Note button at the bottom of your posts.

Thank you.

Will do!

The use case example here is to have non-code-savvy clients be able to only access the Posts/Categories area of the site for management (this is directly acknowledged in the ACF+Loopers videos posted above). The difficulty I’m running into is attempting to adapt the post-focused knowledge resources here to instead use arbitrary categories as a looper source (extended meta implemented by ACF).

I think of the above as basically the same general goal of using X or Pro’s menu elements, but also needing to access meta (not just links, but images as well).


Specific use case / goal:

The category buttons pictured below are non-dynamic, and link to the appropriate archive page. I’d like to pull them in with a looper because I’m 99% sure the client will have a need to add to or edit them, but there are other categories on the backend that should NOT show up here.

The easiest options for targeting categories that I can currently see (without developing out template code) would be:

  • [Currently Testing] Add an ACF field to categories, and use a specific option IN that field to control the looper provider.

  • [Untested] Add categories to a menu using the regular Appearance>Menu options, and then use the menu as a looper provider source (while hoping that the categories’ metadata gets pulled in as well this way). Do we know if this is possible by chance?

For a gorgeous example of how this could be repurposed easily, look at the website for Porsche (car manufacturer), specifically the header’s navigational dropdown thingy.

If this still isn’t clear, I’ll drop the site login stuff! Thanks for your patience.

Put a simpler way than my above “splat”:

The All Terms option for the looper provider is SO close in functionality, I just want to be able to target specific ones (using exclusions) without creating a custom post type or function at this point… if possible.

Now, we could decide on a string that targets arbitrary terms based on existing terms’ IDs (probably with an extension added to the functions.php file), but 1) it’s not easily-extensible for the client, dynamically and 2) if I can figure this out for ACF specifically, that means I can reuse this knowledge to target literally ANYthing I can slap an ACF field on.


Note for posterity: this is technically “solved” from past documentation involving the get_categories() function which can be implemented to bang out this use case, but as noted above… if a way exists that doesn’t require writing code to extend Cornerstone or ACF it’s the better practice IMO

Hello @Rule72,

Regretfully at this time the Looper Provider All Terms will display all the terms and there is no option to exclude a particular category. Your best solution is to use a condition when displaying the categories and it will be hidden if the category is the one that you want to hide.

Take this screenshot as an example where I do not want to see the Events category in my terms list:

Hope this helps.

1 Like

Interesting! It hadn’t occurred to me to use Cornerstone’s conditional logic to solve this problem; that works for this topic’s needs, thanks!

Follow-up Task #1

The next deal; is there any documentation you can point me towards to help solve the need to add a “show all” option if looper count exceeds # amount? (Or, should I open a new thread?)

I’m guessing it would be to use a condition expression, so would the string be similar to {{dc:looper:count}} …?


Follow-up Task #2

On a similar note… if I set the categories up as above, and then want to pull posts as a button underneath… how might I ONLY target the posts within the looper consumer’s output category? This didn’t work rofl.

Hello @Rule72,

You can apply a condition that is something like this; using the Number Expression: {{dc:looper:count}} > desired #.

For your Followup #2, please check out this video first:

Hope this helps.

1 Like

Dope, #1 is closed.

For #2… here’s the setup so far:

image

I have a section that is set up to pull through categories, then consume as an off canvas element (as a result of the previous discussion in this thread) and using conditions to remove the ones I don’t want displayed.

image

The Ask:

When a user clicks the toggle, I want to dynamically display a post grid in the off canvas’ content. So I’ve dropped a div in the content area to act as another looper provider. The part I’m wrestling with to close this topic out is targeting based on the parent…

I thought at first that the new provider would pick up on the parent’s looper, but it makes sense that it doesn’t by default. So next, I thought that category_name={{dc:term:name}} or variations would do the trick (i.e. search for the parent provider/consumer), but so far I’ve struck out. :stuck_out_tongue:


Now I’m looking through the video dropped above, is some URL passback / button magic the most advised route needed here to achieve this function? If so, I can take that route (using a button that triggers a hidden modal’s toggle hash), but it doesn’t seem the most elegant .

Hello @Rule72,

Thanks for updating in!

In your first looper, you use the Looper Provider All Terms. You have displayed each category by consuming in. In your Looper Consumer, you may use the Modal Element and then insert another Looper Provider Query String which should display the post items under that particular category. It should work as I have tested it on my local installation:

Modal Element Settings:

Hope this helps.

Thanks for taking the time to rework this! I’ll step-by-step it based off of your reply. The number Four here is the part I’m stuck on.

One

First, I use a “Terms (Minimal)” element.

Two

Next I kill all the terms I don’t want with a condition.

Three

Now, I drop in a [whatever] and set it up as another provider (swapping out for the text object)…

Four

Step three is working, but these are just all the posts only (not the parent category’s posts) so I’ll need to set another looper provider as you said… and now I start to devolve in my understanding. :stuck_out_tongue: I know that the Provider needs to:

  • Read the parent’s term dynamically,
  • Pull said term, then…
  • Display posts within said term.

In my mind, either a Query String along the lines of category_name={{dc:term:name}} or the following screenshot, or even a Looper Provider set to “Dynamic Content” with {{dc:term:name}} should theoretically do this.

image

Clearly my thinking is flawed, since the result is null and any variations I’ve tried so far break the loop. Insight/advice is extremely welcome.


Side tangent:

In terms of general Cornerstone theory… my previous understanding of loopers and dynamic content was that, unless the provider setting explicitly “exited” the builder/DOM hierarchy, a dynamic content object would just climb parents until it found a source. Does the Looper Provider field behave differently than, say, using a dynamic content object in an element’s text field?

Thanks again for your time on this, I recognize that this thread is lengthy and getting fairly specific – something I try to avoid putting on your team when possible.

Hello @Rule72,

Be informed that each looper provider is independent. You can loop to something else and then nest another loop that may or may not related to the parent loop.

Can you please provide us access to your site instead? We need to check your element structure and your Looper Provider/Consumer settings because it is very hard to guess the output with a different layout or settings. You can create a secure note in your next reply with the following info:
– Link to your site

  • The page you are editing as well
    – WP login URL
    – WP username
    – WP password
    – WP Administrator Role
    - Confirmation that we can access and make changes to your site

To know how to create a secure note, please check this out: How The Forum Works

Thank you in advance.