How to Show or Hidden Categories on page in WordPress?

Goto your respective page template file, default is page.php and the following code <?php if (is_page(‘Food’)) { $catID=11; } elseif (is_page(‘Cooking’)) { $catID=12; } ?> To get the category ID, navigate to dashboard>posts>categories> Click on the respective category, and see the url, it must be something like this wp-admin/categories.php?action=edit&cat_ID=11 take the value of cat_ID in … Read more

create function to call category name and slug

You don’t need to hook the dw_get_category() function. Simply do it like this: function dw_get_category() { global $post; $categories = get_the_category($post->ID); if ( $categories ) { foreach ($categories as $category) { $dw_category_slug = $category->slug; $dw_category_name = $category->name; } } else { $dw_category_slug = ‘utopia’; } $dw_category = array(‘name’ => $dw_category_name, ‘slug’ => $dw_category_slug); return $dw_category; … Read more

Load the last post of a category

Hook template_redirect and check if it’s a category archive page, if so get the category ID from query_vars and query_posts for a single post from that category, which by default should be the most recent, then wp_redirect to the post’s permalink. This code would go in your theme’s functions.php file: function my_category_redirect() { if ( … Read more

Add class to current post in query_post

save the main current post id into a variable and compare it in the loop with the current post id; example: <?php $this_post = $post->ID; ?> <?php $temp_query = $wp_query; ?> <?php foreach(get_the_category() as $category) { $cat = $category->cat_ID; } query_posts(‘orderby=date&cat=” . $cat . “&order=desc&posts_per_page=-1’); while( have_posts() ) : ?> <span<?php if( $this_post == $post->ID … Read more

Exclude category from drop down list form

try: <?php $cat_to_EXCLUDE = 50; $cate_id = retrieve_cat_data(true); $cate_name = retrieve_cat_data(false); for ($i = 0; $i < count($cate_name); $i++ ) { ?> if ($cate_id[$i] != $cat_to_EXCLUDE){ <option value=”<?php echo $cate_id[$i]; ?>”><?php echo $cate_name[$i]; ?> </option><?php }} ?> update: if you search your theme’s functions.php file i bet you will find a function named retrieve_cat_data anyway … Read more