Suppress flexslider on posts page for Sparkling WordPress theme

I want a slider on the homepage but I don’t want it to show up on the posts page. how would I go about that?

http://www.cb550-cafe-build.com/

“the build” is my posts page

Thanks!

Hi @tomkennedy,

I hope you are well today and thank you for your question.

I can see the slider on the homepage http://www.cb550-cafe-build.com/ of your site but not on your “the build” posts page here http://www.cb550-cafe-build.com/the-build/

Have you managed to remove the slider from “the build” posts page?

Please advise.

Kind Regards,
Movin

Im looking to suppress the slider category on the posts page. So slider 1 will be on the homepage only.

Hi @tomkennedy,

Thank you for your reply.

Im looking to suppress the slider category on the posts page.

Do you mean on “the build” posts page you want to display the slider having posts from all categories and from any specific category defined in the Theme options?

So slider 1 will be on the homepage only.

So first slider displayed on the home page will display the posts from the category set in the theme options and the second slider displayed on “the build” posts page will display the posts from all categories.

It is correct?

Please advise.

Regards,
Movin

No slider with ex. category “no-show-slider” will display on posts page at all. So they are exclusive to the home page.

Hi @tomkennedy,

I didn’t understand the replies that you have posted previously and therefore i am not sure what you are trying to achieve so could you please describe it a bit more in detail from start?

Sorry for any inconvenience caused.

Regards,
Movin

Ok from the beginning:

I have set up the slider on the homepage. http://www.cb550-cafe-build.com/

The slider category is “slider”.

The slider shows up as a post on the posts page as a post http://www.cb550-cafe-build.com/the-build/

I DO NOT want the slider to show up on the posts page.

I ONLY want the slifer to show up on the home page.

Thanks Man I hope thats clearer. I feel like maybe if the posts page had some kind of “get posts”

I am curious too how to get this done.

The question is clear: we want to exclude the slider category posts to apear on the blog/post page.
I only want to use this category to show header images on the homepage.

And therefor, is it posible to remove the link on the slider?

Hi @tomkennedy,

Thank you for making it clear again and sorry for taking this much time to know your requirements.

Now i think i understood your requirements to exclude the posts from the category which is set for slider and to achieve this you can use the following custom solution specially developed for you.

You can use the following code either by adding it in the functions.php file of your child theme or by using the attached small plugin containing this code.

function exclude_category( $query ) {
	if( ! is_category() && of_get_option( 'sparkling_slider_checkbox' ) == 1 ){
		$slidecat = of_get_option( 'sparkling_slide_categories' );

	    if (  $query->is_main_query() ) {
	        $query->set( 'cat', '-'.$slidecat );
	    }
	}
}
add_action( 'pre_get_posts', 'exclude_category' );

Best Regards,
Movin

Excellent!
Thanks movin.

One more thing…

De posts show up in the recent posts widget in the sidebar.
Can you provide a solution for that too?

Hi @estone,

You are most welcome here :slight_smile:

De posts show up in the recent posts widget in the sidebar. Can you provide a solution for that too?

To resolve this issue you can use any of the following Extended Recent Posts Widget plugin to display recent posts in the sidebar which are not attached to the category set for the slider category.

http://premium.wpmudev.org/blog/wordpress-recent-post-plugins/

Cheers,
Movin

Thanks Movin, not sure why this guy tried to jack this thread with a separate issue. Hey estone create your own thread!

Wow, thanks for the kind words tomkennedy.

I was only trying to help:
https://colorlibsupport.com/t/suppress-slider-on-posts-page/#post-24974

I had the exact same question, so no need to create another thread.

Right but then you started talking about posts in the sidebar? That’s not the same question.

I gotcha, sorry I didn’t realize your follow up was related to post suppression. Sorry bout that estone!

Hi @estone,

@tomkennedy is right that you should create your own thread for your question instead of replying on others thread as it makes the thread messy and hard to read.

If you want to you can also add reference of this thread in your newly created thread.

I am sure you understand this.

Thanks,
Movin

A very important feature that should be selectable in the theme options.

Btw, I created a child theme where I added such an option in the theme customization. I noticed that it does not work using the child theme concept.

The reason is that changes need to be made in inc/customizer.php. But customizer.php is included via “require” in the parent theme functions.php (not via “require_once”) and none of the functions declared in customizer.php are checked for existence first (if ( ! function_exists( … ) ) …). So there is no way to get around that without changing the parent theme. And that kinda beats the child theme concept.

May I suggest to do either one of the above in the next release?

There is another change that I suggest that goes along well with hiding the slider category from post listings. And that is not to link the slider images to the posts. I found a spot in extras.php, function sparkling_featured_slider. The inner while loop looks like this now:

while ($query->have_posts()) : 
   $query->the_post();

   echo '<li>';
   // echo '<li><a href="'. get_permalink() .'">';
   if ( (function_exists( 'has_post_thumbnail' )) && ( has_post_thumbnail() ) ) :
      echo get_the_post_thumbnail();
   endif;

   echo '<div class="flex-caption">';
   if ( get_the_title() != '' ) echo '<h2 class="entry-title">'. get_the_title().'</h2>';
   if ( get_the_excerpt() != '' ) echo '<div class="excerpt">' . get_the_excerpt() .'</div>';
   echo '</div>';
   echo '</li>';
   // echo '</a></li>';
   endwhile;

As you can see, I commented out the < a > tag and used a plain < li > tag.

Best regards
George

Hi again,

I noticed something weird, the fact that the Slider category posts did not show up in my posts lists in the admin backend anymore. First I thought I lost data but then I realized it was the main query restriction code in functions.php.

The suggestion above was:

if ( $query->is_main_query() ) {
   $query->set( 'cat', '-'.$slidecat );
}

But obvisouly, the main query is also the one that is used in the admin interface, thus, your slider posts do not show up anymore. So I extended the code as follows to just apply it to the home page when set to “Latest posts”:

if ( $query->is_home() && $query->is_main_query() ) {
   $query->set( 'cat', '-'.$slidecat );
}

Btw, this would also be a good spot to restrict the home page posts to just the News category (or any other you want). The News category usually has the ID 1. But you can use any other.

if ( $query->is_home() && $query->is_main_query() ) {
   $query->set( 'cat', '1,-'.$slidecat ); // Cat 1 = News
}

Best regards,
George