Using L&L Inside a Category Archive

I’m trying to use L&L inside of a Category Archive page to pull the posts that are in that category. But I would also like to do a loop inside of that loop to pull any children taxonomy terms of the current archive and sort the posts into those categories on the page.

Example: Category Archive page = Restaurants
That taxonomy has Breakfast, Lunch, and Dinner sub categories.
I would like to display:

Breakfast:
list all the posts that are categorized as breakfast

Lunch:
list all the posts that are categorized as lunch

Dinner:
list all the posts that are categorized as dinner

Mainly, I’m struggling on how to pull just the current posts of the archive (ie Main Query) and not pull the full taxonomy

Just starting, trying to pull the current posts on this category archive page, this is what I have:

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

I’m guessing it should be terms=current, but that pulls nothing… And if I don’t include that, it just pulls all posts, not the ones on that category archive.

Just a thought, did you try to just loop without specifying the type, taxonomy and term?
Given the code is already in the Taxonomy Archive, it should get the main query data.

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

[Update] Just tested, it works for me in a Taxonomy Archive template (Beaver Themer)

Damn it! I tried that, but it didn’t render correctly. I just tried it again, and it worked, but only once I published the archive :rofl:

Inside the Themer archive template, it just displays the Themer Archive template’s name :man_shrugging:t3:

Thank you Emmanuel!

Now that I have that working, my original question comes into play because this didn’t work. I can’t seem to pull the child taxonomies of the current taxonomy archive. I was hoping this would pull it -
<Loop type=taxonomy_term> like this:

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

Yeah, it’s too easy to get the main query data by removing all attributes… and also not well documented in L&L.
I searched for hours myself. :wink:

About your project to display the current Taxonomy term’s posts and the children as well, i have to investigate.

I don’t think taxonomy_term is not a (post) type

You want to display Posts or Terms?

1 Like

@julia Is it possible to pull the child taxonomies of a main query?

I tried <Loop type=taxonomy_term> without any other attributes. Trying to do this:

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

So from the main query, it would pull the list of taxonomy (children) and then display the posts that fall into each.

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