- This topic has 39 replies, 3 voices, and was last updated 4 years, 5 months ago by Tom.
-
AuthorPosts
-
October 31, 2019 at 9:52 am #1049847Heather
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)?
October 31, 2019 at 3:14 pm #1050063DavidStaffCustomer SupportHi 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
?November 1, 2019 at 8:14 am #1050577HeatherYes. 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
November 1, 2019 at 8:28 am #1050584DavidStaffCustomer SupportYou 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 } ?>
November 1, 2019 at 9:06 am #1050629HeatherOk, 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?
November 1, 2019 at 10:02 am #1050685HeatherAlso, 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:
November 1, 2019 at 10:04 am #1050686Heathersorry 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>
November 1, 2019 at 2:10 pm #1050830DavidStaffCustomer SupportSo 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
November 1, 2019 at 2:46 pm #1050856HeatherThat 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
November 1, 2019 at 4:57 pm #1050932DavidStaffCustomer SupportTo 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.
November 2, 2019 at 8:26 am #1051396HeatherOk, 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!
November 2, 2019 at 8:36 am #1051404DavidStaffCustomer SupportAwesome glad to hear that .
November 2, 2019 at 9:46 am #1051478HeatherSorry, 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>
November 2, 2019 at 7:55 pm #1051669TomLead DeveloperLead DeveloperHi there,
Is there somewhere we can see this issue? I’m having a hard time understanding what’s happening, exactly.
Let me know 🙂
November 3, 2019 at 9:22 am #1052131HeatherI 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
-
AuthorPosts
- You must be logged in to reply to this topic.