Display Categories with Loopers

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.

Will do! I’m dropping the login details now.

Hello @Rule72,

I have checked your layout and then created a new demonstration for you. Before anything else, here is our response to this:

" 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}}"

You are actually partially correct. The Looper Provider ALL Terms returns all the terms. The Looper Consumer pull and displays the terms. When you nest another Looper Provider Query String using category_name={{dc:term:name}}, this second looper will return all posts within the current term.

You can check out my demo in the link I have inserted in the secure note below.

Hope this helps.

Ahh, looks I needed another Provider to re-target the existing term rather than relying on the consumer to read all the way up the chain in this case. Because I didn’t do that, I was left chasing my tail.

Thanks! That should close this.

Hey @Rule72,

We’re glad that my colleague was able to help you with your issue! If you have any other concerns or clarifications regarding our theme features, feel free to open up a new thread.

Thank you.