Hi,
Where can I find the settings so that I can set the number of post that can be viewed on category page? Since setting the number of post that can be viewed on Settings -> Reading -> Blog pages show at most (example 20), the number of post that will be shown on all category page is also 20, which might take time to load on other users. So I want to have a settings as well on how many post which can be viewed on category page. I hope you can help me. Thanks!
If you want to hard code the number of posts shown on a category page and not use the built in function of wordpress, you “might” be able to use visual composer for that but I’ve not done that, or you’d need to modify the category template and manually specify the loop (if you have no idea how to do that, you might need to hire a developer).
Obviously if you only want to show 10 items on the category pages, you would set that from the wordpresss > reading function you’ve already used. 20 is a common number to use, however, and works fine on most websites. Some people do less, some people do more. If your main audience is mobile, obviously 10 is a good number.
Since that function impacts the category pages, you’d then use the visual composer to layout your home page and not be impacted by the “10” settings.
In other words, easier to layout the home page with the theme features, than hack the template for the category pages.
Hi,
@Christopher Thanks!
You can do it like @Christopher suggested or you can add this filter in your functions.php file like this: http://screencast.com/t/68OrWnaX
add_filter('body_class','td_my_custom_class_names_on_body');
function five_posts_on_category( $query ) {
if ( $query->is_category() && $query->is_main_query() ) {
$query->set( 'posts_per_page', 5 );
}
}
add_action( 'pre_get_posts', 'five_posts_on_category' );
Change the $query->set( 'posts_per_page', 5 ); value from 5 to the number of posts you want to display on your category page.
Hope this helps!
Thanks
Hi Lucian,
I really appreciate your assistance since I really need that code. Unfortunately it returns an error on the header of our website with the error:
Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, ‘td_my_custom_class_names_on_body’ was given in /home/website/public_html/wp-includes/plugin.php on line 199
class=”wpb-js-composer js-comp-ver-3.6.8 vc_responsive” itemscope=”itemscope” itemtype=”http://schema.org/WebPage”>
Do I need to add the code on the very button of functions.php? Since that’s what I did. I hope you can assist me again. Thank you in advance for your patience 🙂
Hi,
Now I noticed that I didn’t gave you the code right, I have added by mistake this line add_filter('body_class','td_my_custom_class_names_on_body'); so you have to add only this function http://pastebin.com/Rsqty7FV in your functions.php file and yes at the end, make sure you add it like this: http://screencast.com/t/ukaVQXIZ
I have tested this and should work fine just make sure you remove the previous code and paste this one correctly or remove only the line I have added by mistake.
Sorry about this!
Should work fine http://screencast.com/t/0TjSRumeB
Thanks