• Resolved Sinkadus

    (@niwin)


    Hi

    I have used the plugin Custom Content Shortcode to create short codes that automatically write out the name of certain taxonomies tied to a CPT (the link is an example of that single CPT). Short codes in my page builder look like this:

    Nummer
    
    [field title]
    
    Konstn?r
    
    [field taxonomy=portfolio-category]
    
    Teknik
    
    [if exists]
    [field taxonomy=teknik]
    [else]
    —
    [/if]
    
    Material
    
    [if exists]
    [field taxonomy=material]
    [else]
    —
    [/if]

    But this plugin has been discontinued do to some security issue, so my question is if your plugin could replace this function with similar short codes on my site? I realize I would need to create new short codes and replace the ones in use now, but wanted to check in here before I start the process of trial and error.

    Thanks!

    The page I need help with: [log in to see the link]

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Eliot Akira

    (@miyarakira)

    Yes, Loops & Logic is able to do everything that CCS did and more.

    Your shortcode can be written as a template like this.

    Nummer <Field title />
    
    Konstn?r <Taxonomy portfolio-category />
    
    Teknik
    
    <If check="{Taxonomy teknik}">
      <Taxonomy teknik />
    <Else />
      —
    </If>
    
    Material
    
    <If check="{Taxonomy material}">
      <Taxonomy material />
    <Else />
      —
    </If>

    The syntax is similar, but with some small differences.

    The above template can be saved as a template post, and loaded with a shortcode like [template name=example].

    For further details, please feel free to join the discussion forum.

    Thread Starter Sinkadus

    (@niwin)

    Thanks! Will try to replace CCS with this then.

    Two follow up questions:

    1. With CCS I recently noticed that the short code for “konstn?r” (artist)
    [field taxonomy=portfolio-category]

    Did loop out the name of the artist, but this name was then NOT accessible with the search function on my collection page for all the artwork (https://inuti.se/collection/). Do you think L&L will solve this?

    2. Would it be possible to tweak the short codes and make the looped out names into links?

    Thread Starter Sinkadus

    (@niwin)

    Just checking in, any thoughts of my follow up questions?

    Thread Starter Sinkadus

    (@niwin)

    Also, I started a dev site to try this out, and got everything but the portfolio-category to work (“displayed below title “Konstn?r”). At this link there is first the CCS plugin output, and after the L&L output. As you can se, the artist name is not visible for the L&L output. Can you advice, something wrong in the code you gave me??

    Thanks!!

    Thread Starter Sinkadus

    (@niwin)

    I spoke to soon, actually the ONLY part that worked, of your replacement code, was the first one containing the title:

    <Field title />

    All other parts just didn’t put out anything. I managed to change the next part (Konstn?r) by myself:

    <Loop taxonomy=portfolio-category post=current>
      <Field title  />
    </Loop>

    But both of the next taxonomy (if / else) didn’t work, and I can’t figure out how to get them to work. Can you advice?

    https://dev.inuti.se/collection/fredrik-ehnbom/ic03-2023-006/

    • This reply was modified 1 year, 2 months ago by Sinkadus.
    Thread Starter Sinkadus

    (@niwin)

    Update: with this code I can loop out the taxonomy for “Teknik” and “Material”, but I can’t get it to work inside an “if / else query”. Can you hava a look?

    <Taxonomy teknik>
      <Term title /></Taxonomy>
    Thread Starter Sinkadus

    (@niwin)

    Sorry for nagging, but any chance I can get any help with making “if/else” to work?

    Thread Starter Sinkadus

    (@niwin)

    Okay, so this is from your documentation about if/else:

    <If subject comparison value>
    The condition is true.
    <Else />
    The condition is false.
    </If>

    And this is my code (that you provided, and that is not working):

    <If check="{Taxonomy teknik}">
      <Taxonomy teknik />
    <Else />
      —
    </If>

    I’m pulling my hair here, why is the if/else part not working? Can you please please advice.

    Hi @niwin, kudos on doing some serious troubleshooting there! Sorry our folks ghosted you on this thread after Eliot’s initial reply.

    I think the source of this mix-up is probably the fact that Eliot introduced the concept of the Taxonomy loop shortcut which can be useful and succinct, but kind of obscures what’s going on. If you’re just starting out, that obscuration can make it a little tough to figure out what’s going on and troubleshoot it. I’d recommend playing around with the Loop tag syntax rather than the Taxonomy tag for now.

    It seems like what you’re trying to do with <If check="{Taxonomy teknik}"> is to check if a taxonomy term loop exists and, if so, display the term(s). I see that Eliot suggested that syntax, but if I’m understanding the docs right, the Taxonomy tag is a “shortcut for creating a taxonomy term loop” so you couldn’t just use Taxonomy teknik as-is. Since Eliot suggested it, I imagine it’s an undocumented feature, but I couldn’t help with that since only Eliot knows how that works haha!

    In any case, I’d ignore that shortcut for now and take a look at the Loop tag documentation, specifically the feature that allows you to check whether a loop exists. Using that non-shortcut syntax, you’d end up with a conditional part of your template that probably looks something like this:

    <If loop exists taxonomy=portfolio-category post=current>
      <Loop>
        <Field title  />
      </Loop>
    <Else />
      Do something else.
    </If>

    What I’m doing there is instead of just directly looping through the taxonomy terms as you mentioned you were able to successfully do with <Loop taxonomy=portfolio-category post=current>, I’m instead passing that same information to the If tag to first check if the loop returns anything and if it does, then I actually start the loop and display stuff, and do something else if there’s no data in the loop.

    Hope that helps get you back on track with this!

    By the way, if you need help with other issues down the road, another option is to make a post on the official L&L forum. It’s a much more active community so you might get faster support there on future support requests.

    Thread Starter Sinkadus

    (@niwin)

    Thank you! Also, I was sooo close to cracking it myself, since my solution to get “konstn?r” to work was this:

    <Loop taxonomy=portfolio-category post=current>
      <Field title  />
    </Loop>

    And I tried to fit this within if/else. Probably just missed the “exists” variable…

    Anyway – big thanks! Also: did you see my initial follow up questions, regarding if there is a variable to have the output as links, and my problem with konstn?r looping out okay, but not beeing visible for the search tool…

    if there is a variable to have the output as links, and my problem with konstn?r looping out okay, but not beeing visible for the search tool

    @niwin

    Keep in mind that variables are their own thing in L&L and in any templating/programming language. In the case of L&L, variables are handled by the Set and Get tags. But I don’t think that relates to what you’re actually asking about.

    It sounds like you’re hoping to work with a URL field and make that work as a link. You may want to read about how loops work as a refresher but basically, in your case, once you’ve opened your taxonomy term loop, you can display any fields you want that are supported by that loop type, like the title as you’ve already done, or the URL of the term’s archive page. Remember that L&L is just an extension of HTML, so you’d just use regular HTML syntax and fill the attribute values dynamically with L&L’s dynamic tags. The getting started guide goes through that along with some syntax tips if you need a refresher.

    In your case, it might look like this:

    <If loop exists taxonomy=portfolio-category post=current>
      <Loop>
        <a href="{Field url}" ><Field title  /></a>
      </Loop>
    <Else />
      Do something else.
    </If>

    As far as data “not being visible for the search tool,” I don’t think that’s something L&L can help you with. L&L doesn’t create data, it just allows you to adjust how it’s displayed. If your taxonomy terms aren’t showing up in your search, it sounds like you’ll want to modify your site’s search settings.

    • This reply was modified 1 year, 1 month ago by Ben @ Team Tangible. Reason: added a note about search functionality
    Thread Starter Sinkadus

    (@niwin)

    Yes, that did the trick. Amazing support for an amazing plugin. Will immediately leave 5 star review.

    Thank you so so much!

    Plugin Author Tangible

    (@tangibleinc)

    For the search results, keep in mind that search systems generally rely on modifying the main query on the page (the default loop of that page essentially). That means that if you create a new loop, different from the main loop, it likely won’t be impacted by search. Luckily with L&L you can just output the main loop by using the <Loop> tag without specifying a loop type. For a more specific example you can check out our guide on getting it to work with FacetWP which should be quite similar regardless of the search system you use: https://docs.loopsandlogic.com/docs/how-to/facet-wp-loop-tag/

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Replace ‘Custom Content Shortcode’ with this’ is closed to new replies.