in your code, you are checking the category of a post which is quite random outside of the loop and when the posts have more than one category;
the category ID of a category archive page is usually:
$cat_ID = get_query_var('cat');
Related Posts:
- How can I custom order the results from wp_list_categories?
- wp_list_categories: get latest featured_image of category
- Exclude category by slug for for each loop
- Display page of custom posts?
- Showing current subcategory
- Why is my loop not dynamically grabbing the correct Category and displaying all categorized posts?
- Publish Categories for a particular Author on a given Post
- Loop Problem: Displays same set of post for all categories
- Category ID returns as ‘0’?
- Three Column Loop
- Exclude category from get_the_category
- Display all categories as plain text
- loop inside a loop : search for posts in the same category
- Show all child categories associated to post ID within loop
- Secondary loop cuts off at 10 posts?
- Show last post from multiple categories using wp_list_categories
- loop mix my child-category and parent-category
- Jquery Slider for profile template
- Get excerpt using get_the_excerpt outside a loop
- Inject post (from specific category) between posts in Loop
- how to upload image using wp_handle_upload
- Avoiding using a loop to access a single post
- Adding ‘current_post_item’ class to current post in the loop
- WordPress Alphabetical Glossary close div in loop
- Listing all posts from current category on page
- How to make multiple Column in archive Page?
- Sort Popular Posts by Views for the Last Week
- category__not_in — anyway to use category name instead of id?
- Filtering posts by multiple taxonomies
- Listing Parent, Child and GrandChild Categories and then the PostTitles on Page Template !
- Why do I get `Call to a member function have_posts() on a non-object `? [closed]
- Help with Changing loop.php?
- Adding shortcode closing tag after a loop
- Removing the_content() from the page
- Category Ajax call
- Change front-page layout after x amount of posts ( while in the same loop)
- Transient loop issue
- popular post weekly and monthly
- How can i use the same template file with a widget and category loop?
- WordPress Loop inside Loop?
- Class active for Archive link – looped out
- Filter the loop by categories using checkbox form
- Counter in loop in foreach
- angularjs not displaying all posts
- query_posts() vs get_posts() multiple loops [duplicate]
- ACF custom field in [closed]
- Split wordpress loop to multiple layouts
- How do I make a variable available inside partials?
- Update status of all posts in a category
- is_active-sidebar loop
- why does wordpress ignore the post args?
- Unable to change the “Read more” text inside the_excerpt
- Display Post Author Link above the loop
- Conditional: IF current user has NOT commented on current post (not including post author)
- Change post order by meta key, per post basis
- Query Nopaging action not having effect
- issue with if/elseif in_array inside foreach loop display only one post
- How do i find and restore a sidebar that i accidentally deleted? [closed]
- Posts not showing
- Inserting CPT and static content at every X post, is this possible?
- loop through posts and display inserted media and post title as a link
- using update_user_meta to rank users
- Can’t grab author info outside of the loop
- Problem: retrieving parent category’s first post
- How to tell if all posts are only in one category?
- How to get post category and author name for cusmot API?
- How do I set the Stewart Search Template to return only published posts in the result
- Include last post date in get_categories loop
- how tho change number of posts in loop from specific categories
- WordPress posts in the loop not stacking side by side
- How to separate post titles with a comma in the loop?
- error in specific category loop
- Trying to get property ‘post_content’ of non-object
- Pagination for a cpt filtered with a category
- WordPress loop : how to exclude some posts with their status?
- Trying to display all posts in a category
- Create an archive page(loop) for edd products (music files) with an audio player?
- WordPress Pages in an Array
- the_content() keeps repeating itself
- Show different Google Map markers for different post_meta values
- Foundation modal in wordpress php loop
- Multiple Post Repeat for Related Post Loop by Category
- My loop of random posts drags in comments of said random post
- Why my title change the last post title in my loop?
- Have multiple loops on a page appear after/between page content
- How to get multiple loop in category.php, my scripts becomes madness
- How to fix pagination for custom loops?
- Get gallery and product gallery images full size
- Error trying import one category on page
- Custom Category Page Not Working [duplicate]
- display only parent replies count in index.php
- using the loop on a page
- Eliminate duplicates in a foreach loop [closed]
- Tag custom loop show posts
- While loop inside another while loop
- Do not show all post from all categories, just show posts from category in current loop
- Fix html inside a for loop [closed]
- Display all posts in a page code for template
- Insert multiple custom components after x-number of posts
- Use Base-URL with Query-Loop