• Hi!

    I’ve written the following code because I want to show post titles that are marked with the category “front-page-news” to logged out users, but only provide an actual link on the title to the content that has been given the custom taxonomy “Role” term of “general-public.”

    My code is as follows:
    [is logout][loop type=post count=5][if taxonomy=category term=front-page-news relation=and taxonomy_2=role term_2=general-public compare_2=not][field title, field date][br][else][field title-link, field date][br][/if][/loop][/is]

    I’m not getting anything in the results. What am I doing wrong?

    Also, I’d like to be able to link the titles that DO NOT have the term “general-public” to our page that tells the user that he/she must login to access this content. I wasn’t sure where to put that code or how to do it.

    Thank you!

    https://www.ads-software.com/plugins/custom-content-shortcode/

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

    (@miyarakira)

    This part:

    [field title, field date]

    ..should be..

    [field title] [field date]

    to link the titles that DO NOT have the term “general-public” to our page that tells the user that he/she must login to access

    It looks like this is the first [if] condition, so inside it, you can display the title link of the target page by name:

    [field title-link name=login-page]
    Thread Starter gailwingate1

    (@gailwingate1)

    Hi,

    So this is what I changed the code to:
    [is logout][loop type=post count=5] [if taxonomy=category term=front-page-news relation=and taxonomy_2=role term_2=general-public compare_2=not][field title], [field date][br][else][field title-link name=my-membership-options], [field date][br][/if] [/loop][/is]

    But it’s still not working. Nothing is showing up.

    Also, regarding the title-link, if the user doesn’t have access to that content then I don’t want to display a link to our membership page next to the title, I want the user to be taken to the membership page if they click on the title itself. Does that make sense. Ideally, I’d also like to change the color of that link so that I could notate on the page that, for example, the blue links take you to the content, but the red links take you to our membership page to login.

    Thank you!
    Gail

    Plugin Author Eliot Akira

    (@miyarakira)

    Nothing is showing up.

    It will be helpful to narrow down where exactly the issue is, i.e., which shortcode and what parameters. Can you try to test each part of the code block to see where it’s not working as you expect? For example:

    Is the logged-in status correct?

    [is logout]You are logged out.[/is]

    And is the loop and if statement matching any posts? If not, can you check the taxonomy term names to make sure they exist?

    [loop type=post count=5]
      [if taxonomy=category term=front-page-news relation=and taxonomy_2=role term_2=general-public compare_2=not]
        Post matches: [field title]
      [else]
        Post doesn't match: [field title]
      [/if]
    [/loop]

    Finally, does this work by itself?

    [field title-link name=my-membership-options]

    As for making the link red, you can use HTML and CSS.

    <div class="red">[field title-link]</div>

    In your theme or child theme’s style.css:

    .red { color: red }
    Thread Starter gailwingate1

    (@gailwingate1)

    Okay, I think I’ve narrowed down the problem. I simplified the code to the following and it seems to work.
    [is logout]
    [loop type=post count=5]
    [for each=category]
    [if each=front-page-news and taxonomy=role term=general-public]
    [field title-link] ([field date])[br]
    [/if]
    [/for]
    [/loop]
    [/is]

    However, when I include the [ELSE] condition to check if term does not include the value of general-public then it doesn’t work. Nothing is displayed. As in the following:
    [is logout]
    [loop type=post count=5]
    [for each=category]
    [if each=front-page-news and taxonomy=role term=general-public]
    [field title-link] ([field date])[br]
    [else]
    [field title]
    [/if]
    [/for]
    [/loop]
    [/is]

    I then added a second IF statement with the compare=not option and I’m getting the same post displayed in both IF conditions, except the second one has no link. There should be different posts displayed as a result of the second IF statement.
    [is logout]
    [loop type=post count=5]
    [for each=category]
    [if each=front-page-news and taxonomy=role term=general-public]
    [field title-link] ([field date])[br]
    [/if]
    [if each=front-page-news and taxonomy=role term=general-public compare=not]
    [field title][br]
    [/if]
    [/for]
    [/loop]
    [/is]

    Also, when I use [field title-link name=my-membership-options], I get the text “My Membership Options” instead of the post title with that links to My Membership Options.

    Plugin Author Eliot Akira

    (@miyarakira)

    I checked the following condition, and it looks like the and parameter was not working correctly. I addressed this in the newest update, so please see if that improves it.

    [if each=front-page-news and taxonomy=role term=general-public]

    when I use [field title-link name=my-membership-options], I get the text “My Membership Options”

    This is the expected result: it links the specified page’s title to its URL. If you’d like a different label for the link:

    <a href="[field url name=my-membership-options]">...Different title...</a>
    Thread Starter gailwingate1

    (@gailwingate1)

    Hi, the [if each=front-page-news and taxonomy=role term=general-public] was always working. What I can’t get to work is
    [if each=front-page-news and taxonomy=role term=general-public compare=not]

    This second statement needs to find those posts where the term=general-public is not found. Then I must display the title of these posts but with the titles linking to my-membership-options.

    Regarding the following statement:
    …Different title…
    Is there some way to have the “Different title” actually be the title of the post?

    Thread Starter gailwingate1

    (@gailwingate1)

    Hi! Just checking to see if you had a chance to review this? Any help is much appreciated.

    Thank you!
    Gail

    Plugin Author Eliot Akira

    (@miyarakira)

    Hello,

    I looked into the line which wasn’t working:

    [if each=front-page-news and taxonomy=role term=general-public compare=not]

    Checking the code, I realized that compare=not wasn’t an existing feature. (There was only a way to use not similar to and.) In the newest plugin update, I added this parameter.

    display the title of these posts but with the titles linking to my-membership-options

    This can be achieved like:

    <a href="[field url name=my-membership-options]">[field title]</a>

    ..or a shorter and more recommended method:

    [link name=my-membership-options][field title][/link]
    Thread Starter gailwingate1

    (@gailwingate1)

    Hi! Well it worked great! Wow, thank you.

    There is still one more problem I’m having, however. The [else] clause isn’t working for me. I have the following:

    [is logout]
    [loop type=post count=5]
    [for each=category]
    [if each=front-page-news and taxonomy=role term=general-public]
    [field title-link] ([field date])[br]
    [if each=front-page-news and taxonomy=role term=general-public compare=not]
    [link name=my-membership-options][field title][/link] ([field date])[br]
    [/if]
    [/if]
    [/for]
    [/loop]
    [/is]

    This works, but the content isn’t ordered according to latest date. All of the posts for the 1st IF are displayed, then all of the posts from the 2nd IFs are displayed. They should be merged together and ordered by date which would happen if I could use the ELSE clause. What is the problem?

    Thank you again for all of your help!

    Plugin Author Eliot Akira

    (@miyarakira)

    The follow part needs to be changed, because tags of the same name cannot be nested within each other.

    [/if]
    [/if]

    You can either nest them using a prefix:

    [if each=front-page-news]
      [-if taxonomy=role term=general-public]
        ...matches both conditions...
      [-else]
        ...only matches first condition...
      [/-if]
    [/if]

    ..or separate them:

    [if each=front-page-news and taxonomy=role term=general-public]
      ...matches first condition...
    [/if]
    [if each=front-page-news and taxonomy=role term=general-public compare=not]
      ...matches second condition...
    [/if]
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘To link or not to link’ is closed to new replies.