Using L&L Inside a Category Archive

@avanti - Both. So this is what it would look like NOT on an archive:

<Loop type=taxonomy_term taxonomy=local_category>
  <h2><Field title /></h2>
  <Loop type=local_favorite taxonomy=local_category terms="{Field id}">
    <Field title />
  </Loop>
</Loop>

I want to do the same, but on the taxonomy archive so it only pulls the main query

It’s almost like I need an attribute called ‘children’ like they have for ‘parents’ on taxonomy_term: Taxonomy Term | Tangible Loops & Logic

Are the child terms posts marked with the parent term too?
For instance, are the Beakfast Posts marked as Restaurant too?

Yes. Is that a problem?

No, if they are, they should show up in the Restaurant Taxonomy Archive along with the Posts just marked as Restaurant (and no child term)

And you would just loop without any attribute:

<Loop>
  <Field title />
</Loop>

The problem is I’m not able to pull just the Breakfast, Lunch, and Dinner child terms while on the Restaurant archive

I can pull all of the posts that fall inside of Restaurant with the plain <Loop>

But I want it to be this instead:

Breakfast

  • place 1
  • place 2

Lunch

  • place 3
  • place 4

Dinner

  • place 5
  • place 6

Ah, you want to sort the output

Yeah, I want a loop in a loop.

Outside loop is child taxonomy. Inside loop is posts inside that child taxonomy.

Like I said, this works outside of the archive to do just that:

<Loop type=taxonomy_term taxonomy=local_category>
  <h2><Field title /></h2>
  <Loop type=local_favorite taxonomy=local_category terms="{Field id}">
    <Field title />
  </Loop>
</Loop>

Now I need to figure out how to do that to pull the child taxonomies on that archive page
Which is why I thought something like this would work:

<Loop type=taxonomy_term>
  <h2><Field title /></h2>
  <Loop>
    <Field title />
  </Loop>
</Loop>

Too complicated for me.

In case it helps a little, i got this that lists all the top level Category terms, then the children terms under each:

<Loop type=taxonomy_term taxonomy=category parents=true>
  <Field title /><br>
  <Loop field=children>
    – <Field title /><br>
  </Loop>
</Loop>

Returns something like:

Cat 1
Cat 2
– Cat 2.1
Cat 3

Cat 2.1 being a child of Cat 2

L&L misses so much examples in the doc compared to CCS! :pensive:

Thanks for giving it a go! Hopefully @julia has an answer :slight_smile:

1 Like

I found something new to output the current Archive term:
field=archive_term

<Loop field=archive_term parents=true>
  <Field title /><br>
  <Loop field=children>
    – <Field title /><br>
  </Loop>
</Loop>

Which will return, if you’re in the Cat 2 Archive:

Cat 2
– Cat 2.1

The current Archive term and its child terms

I find confusing to have a field attribute in the <Loop> tag…

Wow. That’s getting closer. I just tried to put a loop in a loop in a loop, but that didn’t work :rofl:

This is what I did:

<Loop field=archive_term>
  <Loop field=children>
    <h2><Field title /><br></h2>
    <Loop>
      <Field title /><br>
    </Loop>
  </Loop>
</Loop>

And this is what it output - same posts under each child tax term… :man_shrugging:t3:

I made the same test, unfortunately, the nested loop returns all posts of the current Archive, no way to exclude/include posts having the parent or child term. :wink:

L&L mysterious way…

Hi Zach,

I’m sorry I wasn’t able to respond sooner. Could you see if the following code gets closer to what you need?

<Loop field=archive_term>
  <Loop field=children>
    <h2><Field title /></h2>
    <Loop field=posts>
      - <Field title /><br>
    </Loop>
  </Loop>
</Loop>

The first loop gets the current taxonomy term in the category archive page. The second loop gets that term’s children.

The third loop gets posts that belong to each child term. This is a newly added feature in the plugin version published this week. It’s equivalent to:

<Loop type=post taxonomy="{Field taxonomy}" term="{Field id}">

Thanks for taking a look. I updated and tried your suggestion, but it’s only outputting the taxonomy:
Screen Shot 2022-04-27 at 12.57.23

This was the closest I got before: Using L&L Inside a Category Archive - #18 by zack

I see, so <Loop field=posts> is not working as expected. Hmm, I wonder why that’s empty…

Just to clarify, in this expected result:

Breakfast

  • place 1
  • place 2

Do the posts “place 1” and “place 2” have the child term called “Breakfast”, or do they only have the parent term “Restaurants”?

Yes, that is the correct expected result.

Breakfast

  • place 1
  • place 2

Lunch

  • place 3
  • place 4

Dinner

  • place 5
  • place 6

And each of those have the child term (so place 1 has Breakfast as a term)

One thing that could have a difference is that I have removed the parent term from each, so none of them have Restaurant as a parent term. They only have the child term.

Oh, I forgot to mention, the field=posts is a newly added feature in the latest plugin version 2.4.1. Could you check and update the plugin if necessary?

EDIT: Oops, never mind, I see you did update the plugin. OK, I’ll dig deeper and see if I can figure out why it’s not working as excepted.

Hi Zack,

I figured out that Loop field=posts was getting posts belonging to a child term, but only from the post type post. In the newest plugin version, this has been changed so it gets posts from any post type.

So the following should work now:

<Loop field=archive_term>
  <Loop field=children>
    <h2><Field title /></h2>
    <Loop field=posts>
      - <Field title /><br>
    </Loop>
  </Loop>
</Loop>

I made other improvements related to taxonomy query, taxonomy term loop, and better support for taxonomy archive page.

That includes terms=current for the post loop, which you tried before. It should work now too:

<Loop type=local_favorite taxonomy=local_category terms=current>
  <Field title />
</Loop>

Wonderful. That worked :raised_hands:t2: Thank you for working on that!

1 Like