Condition in a looper, comparison to outside the looper

I am working on a single post layout for a custom post type. It has an ACF field group attached to it.
Each post of the post-type belongs to a “Chapter”. The chapter name is one of the fields of the filed group.
On the layout, I have set up a Div with a looper provider (query builder). It loops through all posts, with the additional condition (Meta values) that the looped posts should have the same chapter name as the current post.
This works, and I can consume all posts within the specified (=current) chapter, I can print their title, and I can link to them.

I use this to create some sort of “table of content” for the current chapter. In the table of content, I want all other posts to be cross-linked, while the current post should appear in a different styling (no link, bold). I thought I do this by showing the looped post titel twice: as a button (with link) and as bold text (without link); and use conditions to hide either the button element (if looped post = current post) or the text element (for all other posts in the loop).

My problem: Once I am within the looper, I seem to have no access to info about the current post that I am on. For example, {{post.titel}} gives me the titel of the looped post, not of the current post. I have tried many of the dynamic content fields that are available, but everything seems to live in the context of the active looper. Is there ANYTHING that is still available inside the looper, that references the current post that I am in, and that I can use in the condition to show/hide the text/buttopn elements?

Hello @striata,

Thanks for writing!

You can use depth. For example:
{{ looper.field({"depth":"1","key":"post_title"}) }}

Check out this documentation on Loopers:

Best Regards.

This doesn’t work. depth with another value than 0 does not return anything. Also, I don’t really have a parent looper, the “parent” is the single post itself.

Hey @striata,

To access information about the main post (the page you are currently on) from inside a Cornerstone Looper Consumer where the post context has shifted, you can try the method below.

  1. Select the parent element (the Div or Row that hosts the Looper Provider).

  2. Go to Customize > Parameters in the element settings and define a JSON parameter:

    {
      "original_post_id": "{{dc:post:id}}"
    }
    

    Because this parent element resides outside the consumer context, {{dc:post:id}} correctly resolves to the ID of the main page you are viewing.

  3. Inside your Looper Consumer, you can now access this saved parent value anywhere using:
    {{dc:param:original_post_id}}

  4. Set up the Conditions on your two elements inside the loop:

    • Bold Text (Current Post): Set the condition to show if {{dc:post:id}} is {{dc:param:original_post_id}}.
    • Button Link (Other Posts): Set the condition to show if {{dc:post:id}} is not {{dc:param:original_post_id}}.

If that does not help, please provide the following info in a Secure Note.

  • WordPress Login URL
  • Admin username and password
  • Page URL where we can see the issue

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

Thanks.

1 Like

This worked perfectly. Thank you!

1 Like

You are most welcome, @striata