[Support request] Limit display rule to Category AND Tag Together

Home Forums Support Limit display rule to Category AND Tag Together

Viewing 15 posts - 1 through 15 (of 40 total)
  • Author
    Posts
  • #1049847
    Heather

    I am trying to use a hook to bring in a “back to blog” link. This works fine for blog archive pages, however I have pages that are pointing to a specific tag archive: so /blog/tag/webinar

    Within that tag archive, I have categories that have a custom link leading to an archive page of webinars in that category, so: blog/category/devops/?tag=webinar

    I want to create a link for this page saying “back to webinars”, so I set the display rules to Post Category Archive – All Archives and Post Tag – Webinar, but it keeps the link on any normal category archive.

    What is the display rule setting, if there is one, that would allow me to have this link show up on every category associated with the link of webinar? Or do I just have to make a link with the display rule doing to tag – webinar and then category – (insert specific category)?

    #1050063
    David
    Staff
    Customer Support

    Hi there,

    i am not sure i understand correctly.
    So do you want to add the link to posts that are within a specific category eg. develops AND have a specific tag eg. webinar ?

    #1050577
    Heather

    Yes. So it seems like right now when you are adding a display rule to a hook, you can choose a Category Archive -> All categories or a specific one, and then you would add an additional display rule for Tag Archive – All tags or a specific one.
    Unfortunately, when this is done, it will place the hook on both the archive page of the category I want to target, and the archive page of the tag I want to target, but not both of them together.
    Ie: Category of devops, tag of webinar – Link will show up on all devops archive pages AND webinar archive pages, but I need to restrict the hook to only display on a page that targets BOTH devops and webinar together.

    the url I am trying to target is /blog/category/devops/?tag=webinar

    So you can see it’s specifically pulling posts with that category and tag

    #1050584
    David
    Staff
    Customer Support

    You could do something like this. Set the Hooks display rules for the category then add this conditional PHP to the hook to check the tag is present:

    <?php
    if ( has_tag( 'webinar' ) ) {
        // The current post has the tag "webinar";
        // add your link here
    }
    ?>
    #1050629
    Heather

    Ok, do I add this within the hook itself? so the add your link is the link I am trying to add to the page, not the link I had sent above that is both category + webinar.

    Or do I do this in functions.php?

    #1050685
    Heather

    Also, when trying to add it it doesn’t seem to work, but I might be referencing the link incorrectly, I am putting it like this in the hook with php turned on:

    <?php
    if ( has_tag( ‘webinar’ ) ) {
    // The current post has the tag “webinar”;
    Back
    }
    ?>
    #1050686
    Heather

    sorry that didn’t so up properly

    <div>
    <?php
    if ( has_tag( 'webinar' ) ) {
        // The current post has the tag "webinar";
        '<a href="www.google.com">back</a>'
    }
    ?>
    </div>
    #1050830
    David
    Staff
    Customer Support

    So in the Hook try this:

    <div>
    <?php
    if ( has_tag( 'webinar' ) ) {
        // The current post has the tag "webinar";
        echo '<a href="www.google.com">back</a>';
    }
    ?>
    </div>

    The display rules need to be Post Category

    #1050856
    Heather

    That worked great! Thanks.

    So if I wanted to limit a link to just the post category archives for the blog itself, would I do something like

    <div>
    <?php
    if ( tag__not_in( 'webinar' ) ) {
        // The current post has the tag "webinar";
        echo '<a href="www.google.com">back</a>';
    }
    ?>
    </div>

    or

    <div>
    <?php
    if ( tag__not_in(array( 'webinar') ) ) {
        // The current post has the tag "webinar";
        echo '<a href="www.google.com">back</a>';
    }
    ?>
    </div>

    Or something different? Still want to have a general back to blog link that is on any archive without webinar, as they are linking to different pages

    #1050932
    David
    Staff
    Customer Support

    To express ‘not’ something you use an ! like so:

    if ( !has_tag( 'webinar' ) ) {

    But if the link is just to be displayed on the Archive you can use the Category Archive display rule without the extra condition above.

    #1051396
    Heather

    Ok, if I use just the category archive display rule it still displays on all category archives along with the links I made that have conditions, so I end up having 2 links.

    However the above seems to work great, thank you!

    #1051404
    David
    Staff
    Customer Support

    Awesome glad to hear that .

    #1051478
    Heather

    Sorry, one last thing, and maybe this just isnt possible – so I have 3 types of archive pages, 1 for all my posts (blog), one for webinars, and one for case-studies. The last two are tag based, but all 3 have the same 4 categories.

    When using this code, it seems like if I select an archive page for, say, devops, from my blog archive page to see general posts about it, the “back to” link will be either case studies or webinar because it is recognizing that some posts in this category have one of those two tags, so it’s changing the link I am trying to display.

    When I am in the tag based archives, everything works as it should as those posts are already being filtered.

    Is there a solution to this? My code is below to have the not in ! for both case-study and webinar, and my display rule is Category Archive – All Categories. Both the filtered back-to links for case studies and webinars also have the same display rule using the code you provided above.

    <div class="back-to-blog">
    <?php
    if ( !has_tag( array('case-study', 'webinar') ) ) {
        echo '<a href="/blog">Back To Blog</a>';
    }
    ?>
    </div>
    #1051669
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Is there somewhere we can see this issue? I’m having a hard time understanding what’s happening, exactly.

    Let me know 🙂

    #1052131
    Heather

    This page is a category archive for one of my categories, that category only has posts without tags for webinar and case-study. The back to blog link is present

    This page is a category archive, but this category is still showing posts with tags of case-study or webinar in it’s archive, so the back to link is now getting overwritten to back-to-case-study instead of back-to-blog because of the php argument from above I am passing through the link

    This is a link to an archive page for the same category as above, but specifically filtered to only show posts that have that category and the tag of case study, so the back-to-case-study link is appearing in the proper place becase of the has-tag argument given to me earlier in this support ticket

    I need the middle link to have “back to blog” and not “back-to-case-study” because it is supposed to be just a general category archive page, and I want to link those general archive pages back to the blog archive/posts page. The only time a back to case study link should show up, is for pages like the 3rd example.

    I tried to create an exclusion rule for the link (see the post you responded to), but it’s causing the back to case study link to show up anytime something with that tag is present. So how would I make the back to blog link to work on all category archives, while still having a filter for case studies for pages such as the 3rd link.

    If it’s not possible, that is fine too, I will try to figure out an alternative

Viewing 15 posts - 1 through 15 (of 40 total)
  • You must be logged in to reply to this topic.