Support » Plugin: Loops & Logic » Beaver Themer Archive

  • Resolved caffeinatedweb

    (@caffeinatedweb)


    Hi! I’m using Loops & Logic on a site with beaver themer. I’m trying to set a loop that shows a CPT in only the currently viewed archive and then filter that by a secondary custom taxonomy… is that possible? This is what I tried

    <Loop type=project count=1 taxonomy=project_type terms=current orderby=date order=desc >
      <Loop type=project taxonomy=featured terms=featured>
      <div>
        <a href="{Field url}">
        <div class="fl-post-image">
          <Field image size="large" />
        </div>
        <div class="fl-post-text">
          <h2 style="margin-bottom: 0;"><a href="{Field url}"><Field title /></a></h2>
          <p><Field sub_head /></p>
        </div>
        </a>
      </div>
      </Loop>
    </Loop>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Tangible

    (@tangibleinc)

    Hi!
    This is definitely possible! I would approach it this way:

    <Loop field=archive_term><Set term_id><Field id /></Set></Loop>
    <Loop type=project taxonomy=project_type terms="{Get term_id}" taxonomy_2=featured terms_2=featured orderby=date order=desc>
      <div>
        <a href="{Field url}">
          <div class="fl-post-image">
            <Field image size="large" />
          </div>
          <div class="fl-post-text">
            <h2 style="margin-bottom: 0;"><a href="{Field url}"><Field title /></a></h2>
            <p><Field sub_head /></p>
          </div>
        </a>
      </div>
    </Loop>

    The rest of my response is just explanation, so you can just go ahead and copy-paste that code block and it should work 😀

    The Loop tag gets the archive context by default if you just write <Loop></Loop>, but as soon as you add other attributes like your taxonomy filtering that context breaks down. So your instinct to open a project loop with terms=current was correct, however that doesn’t seem to work in my testing. (If you try it on your end again let me know if it works!)

    Because the default Loop context on an archive is the posts in it, you need to open a separate loop to access the current term fields like title, ID and custom fields. You can use <Loop field=archive_term> on archives for this purpose. Inside my archive_term loop I saved the term ID as a variable to pass to the main loop using Set and Get

    The part you were getting wrong is that your nested loops are unnecessary, as you can use up to three taxonomy filters on a single Loop. You’ll find the taxonomy attributes for the post Loop documented here.

    Aside from that, nested Loops only inherit context if you tell them to, so your example could maybe have worked if you passed include="{Field id}" to the inside Loop (assuming the filter priorities work in the specific way we need them to, I haven’t actually tested it):

    <Loop type=project count=1 taxonomy=project_type terms=current orderby=date order=desc >
      <Loop type=project include="{Field id}" taxonomy=featured terms=featured>
      <div>
        <a href="{Field url}">
        <div class="fl-post-image">
          <Field image size="large" />
        </div>
        <div class="fl-post-text">
          <h2 style="margin-bottom: 0;"><a href="{Field url}"><Field title /></a></h2>
          <p><Field sub_head /></p>
        </div>
        </a>
      </div>
      </Loop>
    </Loop>

    Hope that helps!

    Please visit our discussion forum if you have any other questions!

    Thread Starter caffeinatedweb

    (@caffeinatedweb)

    This worked perfectly, thank you so much for your help! This plugin has been a lifesaver for this project!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Beaver Themer Archive’ is closed to new replies.