How to customize my category pages

One way to do it is with the WordPress Template Hierarchy. If your category names/slugs are not likely to change you can have a separate template for each category. For example: category-books.php // will be loaded when viewing ‘Books’ category category-magazines-and-newspapers.php // will load for ‘Magazines and Newspapers’ category This way you can customize each … Read more

Random Featured Image Based on Category

First of all when you call the get_image function pass the post categories slugs as param. Edit your autoset_featured function replacing … } else { set_post_thumbnail($post->ID, get_image()); } … with: … } else { $cat_slugs = wp_get_post_terms($post->ID, ‘event-categories’, array(“fields” => “slugs”)); $image = get_image( $cat_slugs ); if ( image ) set_post_thumbnail($post->ID, $image); } … Then … Read more

get_terms function not returning anything

get_terms just returns an array of terms, it doesn’t generate output. You have to do something with that array to see the results- $categories = get_terms( “category” ); echo “<ul>”; foreach ( $categories as $category ) { echo “<li>” . $category->name . “</li>”; } echo “</ul>”; See the other examples on the Codex page.

How do I query_posts in cat=1 AND not in cat=2

First, never use query_posts, use WP_Query for additional queries, or pre_get_posts to alter the main query. Refer to WP_Query in Codex for a complete list of available arguments. You want to use category__not_in in this case: $args = array( ‘category__in’ => array(1), ‘category__not_in’ => array(2) ); $query = new WP_Query( $args );

Set colors depending on category

Setting aside that you’re incorrectly using query_posts(), the easiest solution is to add a call to post_class(), to output post-specific classes, including .category-{ID} and .category-{slug}: <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?> <li <?php post_class(); ?>><a href=”https://wordpress.stackexchange.com/questions/123066/<?php the_permalink(); ?>” title=”<?php the_title(); ?>”><strong><?php the_title(); ?></strong></a><br /> <em><?php echo substr(get_the_excerpt(), 0,110); ?> … Read more

Create menu locations for each category in wordpress

You’re going about this wrongly, I think. The theme_location parameter for wp_nav_menu() is a template location – i.e. a physical location in the template, as defined/registered by the Theme. It’s not designed for an arbitrary number of locations based on arbitrary user content. If you want to output category-specific menus in specific template locations, you … Read more

Show category with link

EDIT You should look at get_the_category. You are probably looking for something like this as from the codex <?php $categories = get_the_category(); $separator=” “; $output=””; if($categories){ foreach($categories as $category) { $output .= ‘<a href=”‘.get_category_link( $category ).'” title=”‘ . esc_attr( sprintf( __( “View all posts in %s” ), $category->name ) ) . ‘”>’.$category->cat_name.'</a>’.$separator; } echo trim($output, … Read more

Wacky taxonomy in wordpress

WordPress’ terms and taxonomies are spread over three tables in the database. Those tables are wp_terms, wp_term_relationships and wp_term_taxonomy – see the codex article on Database Description for more details. The parent relationship is part of the wp_term_taxonomy table, so you should inspect the differences between your environments in this table. wp_terms does not store … Read more