Display one category in one page

From what I understand, the question is, how can you show only one category on a WordPress Page? What Scuba Kay is suggesting is the default category archive, if you want to go that route, WordPress already has archive pages with your posts for each category without you having to create your own Page. If … Read more

Changing the category permalink structure

The following code changes all links to category archives so they don’t include the parent category: add_filter( ‘category_link’, ‘wpse7807_category_link’, 10, 2 ); function wpse7807_category_link( $catlink, $category_id ) { global $wp_rewrite; $catlink = $wp_rewrite->get_category_permastruct(); if ( empty( $catlink ) ) { $catlink = home_url(‘?cat=” . $category_id); } else { $category = &get_category( $category_id ); $category_nicename = … Read more

Only show category to certain user levels without plugin

If I understand you have some categories, eg: ‘reserved’, ‘people’, ‘landscapes’, ‘personal’ and so on. Now you want that subscribers can see posts in, e.g. ‘people’, ‘landscapes’ categories but not posts in ‘reserved’ and ‘personal’ categories. This is relatively easy, just hook into pre_get_posts and if the request is for a post having that terms … Read more

Adding Custom User Profile data based upon Categories

here is an example //create the user category fields add_action( ‘show_user_profile’, ‘add_user_categories’ ); add_action( ‘edit_user_profile’, ‘add_user_categories’ ); function add_user_categories($user ){ ?> <table class=”form-table”> <tr> <th><label for=”user_categories”><?php _e(“User categories”); ?></label></th> <td> <?php $data = get_the_author_meta( ‘user_categories’, $user->ID ); $args = array( ‘hide_empty’ =>0, ‘taxonomy’=> ‘category’); $categories= get_categories($args); if ($categories){ foreach ( $categories as $category ){ if(in_array($category->term_id,(array)$data)) … Read more

How to only show posts on last child category

There is of course the include_children parameter for WP_Query as part of the taxonomy parameters. Which I suppose should work like this for you: $args = array( ‘tax_query’ => array( array( ‘include_children’ => false ), ), ); $query = new WP_Query( $args ); Or via parse_tax_query for your category archive: add_filter( ‘parse_tax_query’, ‘wpse163572_do_not_include_children_in_category_archive_parse_tax_query’ ); function … Read more

categories on attachment page

If you have WordPress 3.5 this will work. http://make.wordpress.org/core/2012/12/12/attachment-editing-now-with-full-post-edit-ui/ First you need to enable this in your theme, Put this in your functions.php file in your theme root. add_action(‘init’, ‘wpse_77390_enable_media_categories’ , 1); function wpse_77390_enable_media_categories() { register_taxonomy_for_object_type(‘category’, ‘attachment’); } In your image.php or attachments.php file add: $tax = get_the_term_list( $post->ID, ‘category’ ); echo $tax; Then go … Read more

Display only the latest post from multiple categories

i think you’d have to use get_posts 5 different times. what about this: global $post; $posts = array(); //categories you want to pull latest posts from; $cats = (1,2,3,4,5); foreach($cats as $cat): $args = array( ‘numberposts’ => 1, ‘category’ => $cat ); $posts[] = get_posts($args); endforeach; if($posts): ?> <ul> <?php foreach( $posts as $post ) … Read more