Hi, how can I get a slider to autoplay in a category page? Also how can I show only unique posts on category page (i.e., if a post is showing up in the slider, how can I have it NOT show up below)?
Thanks!
Hi,
Add this code: 'autoplay' => '2', like here: http://screencast.com/t/VzmO8sMs
Add this code in functions.php and change that 98 with your featured category ID
add_action( 'pre_get_posts', 'be_exclude_category_from_blog' );
function be_exclude_category_from_blog( $query ) {
if( $query->is_main_query() && $query->is_category() ) {
$query->set( 'cat', '-98' );
}
}
Thanks!
Thanks Marius, I’ll give it a try. I assume it’s possible to do this for more than one category?
Serg
hi,
use coma between values: http://screencast.com/t/EYH2T8fAwcjG
Thanks for you message.
Radu A.
I feel making the category slider auto play and unique is a main feature as it doesnt do its job otherwise and looks messy. will you be making this standard in the future as it will finish off the catergory page?
Hi tagDiv,
My Featured category ID = 2
I using bellow code in file functions.php themes (i append code end of file)
add_action( ‘pre_get_posts’, ‘be_exclude_category_from_blog’ );
function be_exclude_category_from_blog( $query ) {
if( $query->is_main_query() && $query->is_category() ) {
$query->set( ‘cat’, ‘-2’ );
}
}
but it not working exclude post in featured.
my post added 2 categories: cars and featured.
when load site, i see post at featured and cars.
best regards,
Hi,
Please make sure you add the code like this: http://screencast.com/t/dU6XKtP4
Paste the code from below into the functions file:
add_action( 'pre_get_posts', 'be_exclude_category_from_blog' );
function be_exclude_category_from_blog( $query ) {
if( $query->is_main_query() && $query->is_category() ) {
$query->set( 'cat', '-2' );
}
}
I have tested this and works fine, when viewing the featured category page the posts should show only in the slider as we have excluded the featured category http://screencast.com/t/GxyXjEG9y55
If you want other category excluded add the category id like this http://screencast.com/t/EYH2T8fAwcjG
Hope this helps!
Thanks
Hi,
You can go to WordPress Dashboard > posts > categories and hover over one category, the ID of that category will be showed at the bottom of the page, like this: http://screencast.com/t/55R3fQwgydA
Thanks
I did your above steps and I get this error…
http://s16.postimg.org/urcepu10l/watdaaaa.jpg
I don’t understand why this stuff happens to me.. It’s like this theme hates me with a passion.
Please help.
Hi,
The code for should look like this:
add_action( 'pre_get_posts', 'be_exclude_category_from_blog' );
function be_exclude_category_from_blog( $query ) {
if( $query->is_main_query() && $query->is_category() ) {
$query->set( 'cat', '-44' );
}
}
Make sure you copy it properly, let me know if it works.
Thank you, Emil G.
Hi Emil,
It did not work…
I get the same error: Fatal error: Call to undefined function add_action() in /home/leadnrr/public_html/wp-includes/functions.php on line 4632
And Line 4632 is: add_action( ‘pre_get_posts’, ‘be_exclude_category_from_blog’ );
Btw, my Featured category ID is actually : 44, because I erased the Featured category in the beginning not knowing why it was there in the first place.
Hi Lucian,
Actually, I don’t think I got the email, please contact me again via: kevinhan123@hotmail.com
Thank you
Hi,
You have to add that code into theme’s function.php file which you can find in the root of theme files: http://screencast.com/t/X5iuZk1qXXRm
Please make sure you add this right you have added the code into functions.php file found in WordPress’s files that’s why you got that error.
Thanks