Jump to content
Gavin_

exclude categories from carousel

Recommended Posts

Gavin_

Hi

we would like to globally exclude categories from appearing in the carousel. we have about 30 categories and there are 8 that we need to exclude.


function exclude_category( $query ) {

			    if ( $query->is_home ) {

					    $query->set( 'cat', '-1' );

			    }

	    }

	    add_action( 'pre_get_posts', 'exclude_category' );


i found this on another thread here and was wondering if it could be tailored to achieve the exclusion in carousels.

Thanks

Share this post


Link to post
Share on other sites
Rob

It probably can be used that way Gavin, but it would take a developer with skills in functions and hooks to craft it properly. Doing it wrong could break your site, as I'm sure you know. I understand you've done some seriously good coding in past and imagine this isn't beyond your reach, given the fact that you have an example of the hook.


Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites
Gavin_

can anyone advise on how the carousel can be targeted correctly?

thanks

Share this post


Link to post
Share on other sites
Rob

Gavin, I am unsure of how to exclude a category, except for a method I didn't think you'd like. So, let me offer it anyway and let you make your own choice.

In your site, create a new category... for the sake of this example, we will call the category "carousel".

For each post you want to show, add the post to that category. If you have a large volume of posts, you can use an old but still functional plugin called "Batch Cat", available at WP.org.

Then, in the settings for the carousel, rather than exclude, you'd select the carousel category. Only the posts you have added to that category will display, essentially excluding those you do not wish included.

Yes, it's old fashioned thinking, but I'm and old guy.


Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites
Gavin_

Hi Rob,

Thanks for your advice, if none of the pagelines developers can advise on how to target the carousel we will look at your suggestion.

We have asked this in the chat service and been advised to ask it here. Hopefully a developer will be along soon.

thanks

Share this post


Link to post
Share on other sites
Rob

I have no idea when that might be Gavin, as they usually don't work in here. One's on vacation too. I can't be sure when this might be answered, but did flag it for you.


Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites
Simon

Gavin your filter can be reused, just needs some logic added so it does not hijack the main query ;)

Now let me point out, this is a bit of a hack ;) First you have to set the max carousel images to something random, I chose 17.


function exclude_category( $query ) {
if ( $query->is_home && isset( $query->query['numberposts'] ) && '17' == $query->query['numberposts'] ) {
$query->set( 'cat', '-1' );
}
}
add_action( 'pre_get_posts', 'exclude_category' );
[/CODE]

So the filter checks if were on the frontpage, assume thats where you wanted the carousel, then it looks for numberposts being '17' ;) Without this check it will break the main query for your posts.

Share this post


Link to post
Share on other sites
Gavin_

Thanks Simon

that has worked perfect.

:)

Share this post


Link to post
Share on other sites
Simon

The topic was marked as resolved.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Similar Content

    • marshallsolutions
      By marshallsolutions
      For the site https://marshallsirishpub.com I am running
      Wordpress 4.9.4
      Pagelines base theme 1.0.2
      Pagelines Framework 2.5.0
      Specific page not working properly is https://marshallsirishpub.com/photo-gallery/
      I am using NextGen gallery which is activated and showing the pictures in the gallery.  Page was edited to add the carousel and points to the NextGen gallery.  Meta settings and page were both saved.
      When I'm logged into Wordpress I see the following error at the top of the page:
       Carousel 
      THE PLUGIN FOR THE SELECTED CAROUSEL MODE NEEDS TO BE ACTIVATED (FLICKRRSS OR NEXTGEN GALLERY). SETUP PLUGIN →
      The site was hacked last month and it seems the hacker changed some things on the site, but I can't figure out what was changed to make the Carousel not show on the page.
      Thanks.
    • oseehys
      By oseehys+
      The Grams section of Platform 5, is lacking lots of important features, that DMS multigram was having, there is no space for another user ID asie the default user, that was one of the strongest point of multigrams, because the Hashtag option cannot capture everyone, multiple User ID is the default standard for Instagram,  Also there is no carousel or slide on this one, it means now that if you want to display 18 pictures in one page all will be visible at once thats not good engineering.
      My appeal to the Pagelines Team, guys please let the next update have all the DMS Multigrams features that is missing on Platform 5 Grams, that will bring it to its glory...
       
       
    • Queue-it
      By Queue-it+
      Hi,
      Previous webmaster has made short codes assigned to certain categories. For example: [pl_section section="loops" id="003"]  displays all the Job posts for tech. 
      But where can I assign a short code for a certain category? I can't find where to add the loop ID for the category.
       
      Thank you
       
    • Queue-it
      By Queue-it+
      I've created a new post category "Success stories" with Custom Post type UI. (in order to have a different layout for a different post category - blog post one layout, success stories another layout).
      New category "success stories" are "detached" from all the other posts, so they have a different layout, but the problem is that all of the success stories are also having the same exact content.
      So whenever I edit content (e.g. change body text) on one of success story posts, it also changes the content (body text) for all other Success story category posts. 
       
      Question: Is there a way to retain this separate category with it's own layout, and have a different content for each individual post? I'm using Pagelins templates. 
       Thanks in advance.
    • Queue-it
      By Queue-it+
      Hi,
      Is is possible to have different layouts for different Post categories? We have Blog posts, News posts and Case studies that all are posts, but is it possible to differentiate their layouts?
      So far when I change a post layout it affects all Post type pages. Could it be done somehow with creating a separate template? 
      Examples below
      https://queue-it.com/news/
      https://queue-it.com/blog/
       
×