- This topic has 39 replies, 3 voices, and was last updated 3 years, 4 months ago by
Tom.
-
AuthorPosts
-
November 3, 2019 at 9:52 am #1052174
Heather
As a side question – I noticed there is a display rule from Pages, is there a way to use this display rule but for a custom URL?
November 3, 2019 at 8:49 pm #1052503Tom
Lead DeveloperLead DeveloperSo this is your code for the Back to Blog:
<div class="back-to-blog"> <?php if ( !has_tag( array('case-study', 'webinar') ) ) { echo '<a href="/blog">Back To Blog</a>'; } ?> </div>
What’s your code for “Back to Case Studies”?
The Display Rules are only for pages/archives that WP is aware of.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentNovember 4, 2019 at 7:44 am #1052830Heather
<div class="back-to-case-study"> <?php if ( has_tag( 'case-study' ) ) { // The current post has the tag "case-study"; echo '<a href="http://dev.indellient.com/case-studies/">Back to Case Studies</a>'; } ?> </div>
November 4, 2019 at 5:55 pm #1053396Tom
Lead DeveloperLead DeveloperWhat if you do this?:
<?php $tag = isset( $_GET['tag'] ) ? true : false; if ( $tag ) : ?> <div class="back-to-case-study"> <a href="http://dev.indellient.com/case-studies/">Back to Case Studies</a> </div> <?php else : ?> <div class="back-to-blog"> <a href="/blog">Back To Blog</a> </div> <?php endif; ?>
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentNovember 5, 2019 at 7:30 am #1053977Heather
That works! Thank you so much!
The only other thing is that I have an additional page where I need this to happen, so I have a case-study page and a webinar page. I essentially need the same thing so that the webinar pages have “back-to-webinar”. What is the rule I would add in here to allow the 3 links to show up in their respective places (case-study, webinar, blog). Is it an ifelse statement in between?
November 5, 2019 at 7:02 pm #1054391Tom
Lead DeveloperLead DeveloperCan you link me to the webinar page possibly?
Let me know 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentNovember 6, 2019 at 7:17 am #1054940Heather
http://dev.indellient.com/webinar/
It is built in the same way as the case study page. So that page is a tag archive, and the categories have a url like: http://dev.indellient.com/blog/category/analytics/?tag=webinar
if you go to the categories now, it says back to case studies because of the filter, but it needs to say back to webinar.
November 6, 2019 at 9:09 am #1055067Tom
Lead DeveloperLead DeveloperLet’s try this:
<?php $tag = isset( $_GET['tag'] ) ? true : false; if ( $tag ) : ?> <?php if ( 'webinar' === $_GET['tag'] ) : ?> <div class="back-to-webinar"> <a href="http://dev.indellient.com/webinar/">Back to Webinars</a> </div> <?php else : ?> <div class="back-to-case-study"> <a href="http://dev.indellient.com/case-studies/">Back to Case Studies</a> </div> <?php endif; ?> <?php else : ?> <div class="back-to-blog"> <a href="/blog">Back To Blog</a> </div> <?php endif; ?>
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentNovember 6, 2019 at 10:20 am #1055151Heather
This worked wonderfully! Thank you so much, everything works so much smoother now.
November 6, 2019 at 12:01 pm #1055264Heather
Will something like this also work for displaying posts in these areas. So since I have a dedicated page for posts with a tag of case-study and webinar, I do not want them to display on my general blog archive page.
This is fine, until you try to look at a category, and all the posts are there. For example:
/blog contains only posts that do not have a tag of case-study or webinar
/blog/category/devops will show ALL posts with a category of devops, regardless of what tags they have.
Since I already have an archive page for case-study tagged posts with a category of devops (see here), I do not want any of these posts to show up within the general archive page.
So is there a way to use this same logic but for displaying posts? Or only displaying posts if the url has the tag=case-study in it?
November 6, 2019 at 7:33 pm #1055463Tom
Lead DeveloperLead DeveloperHi there,
That would be different code. Are you only trying to exclude posts with those two tags? And they would only be excluded if you’re not viewing those specific tag archives?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentNovember 7, 2019 at 11:52 am #1056274Heather
Well I have this code in my functions.php
//Exclude case study, event, and webinar posts from appearing in blog function exclude_posts( $query ) { if ( $query->is_home() ) { $query->set( 'tag__not_in', array( 182, 180, 166 ) ); } } add_action( 'pre_get_posts', 'exclude_posts' );
Those are the tag ID’s for case-study, webinar, and news. So if you go here you can see that these posts have these filtered on every page, but if you were to go to the archive page for Document Workflow Automation, the first few posts are case-studies that also appear on the Case Studies tag archive page. These category archives should still remain filtered to just show posts, in the same way that the blog archive page is filtered.
Is there a way to do this, maybe with some if / ifelse statements?
November 7, 2019 at 6:40 pm #1056467Tom
Lead DeveloperLead DeveloperHmm, maybe try this:
add_action( 'pre_get_posts', function( $query ) { if ( $query->is_archive( 'webinar' ) || $query->is_archive( 'case-study' ) ) { return $query; } if ( $query->is_archive() ) { $query->set( 'tag__not_in', array( 182, 180, 166 ) ); } } );
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentNovember 8, 2019 at 8:07 am #1057079Heather
So that worked fine, however it ended up filtering those tags even on those specialized archive pages. So for something like the case-study tag archive, when you select a category (document workflow automation link in previous post), it now shows no posts and acts like no posts with that tag exist.
Works great for the blog archive and the plain category archives, so blog/category/whatever – but it seems like it doesn’t register the query when the tag is involved, ie: all my filtered category posts for those tags are now empty across the website.November 8, 2019 at 4:16 pm #1057415Tom
Lead DeveloperLead DeveloperI just edited the code here: https://generatepress.com/forums/topic/limit-display-rule-to-category-and-tag-together/page/2/#post-1056467
Can you give it another shot?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.