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); ?> ...</em>
</li>
<br />
<?php endwhile; ?>
Then, you can use CSS to target li.category-{ID}
.
Related Posts:
- Display one latest post from multiple categories
- How to query post like normal search would do. within search.php page
- Pagination on category.php and tag.php not working
- Posts of specific category on page and excluded from index.htm
- new WP_Query issues
- Get all categories and posts in those categories
- Combine two taxonomies in a hierarchical tree
- How to get posts from two categories with WP_Query?
- Group WP_Query by category
- Exclude categories from search query
- How can I reduce the number of database query calls for this custom homepage?
- WP_Query not looking at child category
- Get page content by category or tag
- Using categories & “stickyness” together
- Does the ‘cat’ argument in query_posts fetch posts from subcategories as well as the given ID?
- List posts by category exclude current post
- Excluding posts from a category but only if they’re not in multiple categories
- What could be causing my wp_query pagination to break?
- Display only the latest post from multiple categories
- Exclude most recent posts from specific category in wp_query()
- Select category in custom query
- How to Check if a Child Category is Being Queried
- Return category slug / title from category ID
- How to show only one post for each categories of taxonomy of custom post that contains a specific custom field
- How to run WP_Query to retrieve attachments to posts only from a particular category?
- How to query posts from specific authors and categories using WP_query?
- Exclude category from loop not working
- How to show in search results posts with a particular tag in a particular category?
- Custom WP_Query for current category (in category.php)?
- List Posts by Category for a Non-Zero, Non-NULL Custom Field Value?
- getting content from main domain to sub-domain using category and WP_Query
- WP_Query() returns null when results exist!
- Ignoring a category in WP_Query still shows the links in next_post_link()?
- 3 Columns, 3 Categories, One Archive, and Pagination
- Five posts from a category in footer
- Post count for category and tag
- Enter a variable in the ‘category_name’ parameter
- Checking for two categories in query_posts
- How do I call posts with a certain tag?
- Modify WordPress SQL Query to pull from within a category
- query order by category
- Get link which associated with a specific category and tag
- Multiple Loops on category.php with pagination on last loop
- How to get latest posts from each category in regular order
- change recent posts based on category
- Order by category titles
- Have parent category contain only one post?
- How to remove specific categories from posts?
- How do I query_posts in cat=1 AND not in cat=2
- List all posts in a category with query_post() function
- Exclude a category from a query that includes its parent category
- Show the latest post from child category?
- Custom loop of a single category, cannot order by date. What am I missing?
- Problem with different query loops (and “main loop”) on category template page!
- query_posts not reading correct categories
- Use premade array as categories in wp_query?
- Pagination for query_posts();
- function query_posts disabling current_page_menu class
- query_posts by category_name and custom taxonomy
- WP_Query – using category__and when one of the categories is 0
- Adding a block with query in homepage
- I need to exclude from a query a category and a few custom taxonomies
- Show multiple categories in query using redux framework variable
- Return category posts with WP_Query
- multiple values in an array for category__and does not work with WP_Query
- Retrieve post tags from from main wp_query
- PHP dynamical conditional post display
- Select posts that match multiple category names, must match all categories listed
- the_category() doesn’t working in wp_query loop
- Displaying links to all posts of the same category on the post page
- Post not found when filtered by category ID
- How to display the 5 latest post titles but allow only 1 in there of a specific category
- Exclude categories from postquery
- Sort posts alphabetically by category/custom taxonomy, insert divider between different types
- Show posts from category specified using a custom field
- query_post problem
- Add class to current post in query_post
- Filter products on category AND tag
- Different post slug based on archive
- Query the title of the page to show posts with matching category in the loop
- Pagination does not work with query_posts()
- Assign a class to first element in category in loop
- How to display products with multiple conditions, product_id and category_id
- Query post only from categories that have subcategories
- category__and works, but why?
- foreach,having wp_query inside, breaks after showing one result
- Display related posts with same category or same tag return blank
- $args Orderby The number
- Querying Multiple Categories With Different Offsets
- WordPress Numeric Pagination with Query String [duplicate]
- Printing direct descendants of a category with WP_Query
- Displaying posts by year
- Show only one category in main query, issues on tag page
- Multiple Categories under one URL, where ‘Front Page’ is used already
- How do i add custom post types to this query?
- How to have a category not show up in query post with page panigation?
- Query pages by category
- Showing one post from each category, paged?
- query_posts problem – need help
- How to retrieve posts from parent category, splitting them per children when displayed?