Just like WordPress documentation page of that code says, that functions is designed to show specific category or categories on your frontpage.
function ar_home_category( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'cat', '3' );
}
}
add_action( 'pre_get_posts', 'ar_home_category' );
I have tested this code on my local website, and it works perfectly.
Please make sure that your category ID is correct and corresponds to that category you need.
Can you tell me how did you get the ID (11) of the category that appears in your code, and where are you puting it?
]]>I want to show only 20 category names in category widget, not posts from certain category.
]]><ul>
<?php wp_list_categories( array(
'orderby' => 'name',
'include' => array( 3, 5, 9, 16 ),
'title_li' => '',
) ); ?>
</ul>
This code will show you the category names with a link. Just change the numbers to the IDs of your desired categories that exist in your website.
You can past that code in the place when you want to show it in any file of your current theme. For example sidebar.php.
If you want a solution more quick and practice for beginners, you can use the Display Categories Widget plugin.
Let me know if this helps you.
]]>Glad to help you.
]]>