WordPress rewrites rules invisibly translate pretty permalinks to the non-pretty format internally, and set the appropriate variables and load the requested page, you don’t need to do anything in your template to load posts from a category on a category page.
The cat
query var specifically will be set to the ID of the requested category, not the name.
That said, this:
$my_category = get_query_var('cat');
echo $my_category;
should print the selected category ID on a category page. If it’s not, we’d have to see your code to help you further.
Also, have a look at the $wp_query
global to see all query vars set on a particular page:
global $wp_query
print_r($wp_query);
Related Posts:
- Get the blog page URL set in Options
- What’s the difference between home.php and index.php?
- How to set permalink structure via functions.php
- How to move page templates to custom folder?
- Plugin for custom sort order for categories?
- Page template in two level deep folder
- Different ways to display title
- Is it possible to manipulate the list of page templates?
- How Do I Programmatically Force Custom Permalinks with My Theme?
- Different wordpress 404 template for different post type [duplicate]
- Posts in multiple Categories different single.php
- How to get the url to tag & category base set by the user?
- Retrieve the template directory URI via global or get_template_directory_uri() every time?
- Add a preview to a WordPress Control Panel
- Add a #hash to the links in my custom menu
- How to load different CSS in different Header?
- Template tags to display custom post type posts in category template?
- Returning Variables back into a template
- How to override BuddyPress 3.0 bp-nouveau theme files?
- Any tag pagination page (except the 1st page) loads index.php template instead of tag.php
- New template, where to place CSS?
- Link won’t show using the_permalink();
- Check if password protected post is visible
- What is the best way to handle multiple calls to get_template_directory_uri() and similar functions?
- Add theme templates for child categories into the template hierarchy
- Where can I access my custom page template?
- Theme development question regarding layouts
- WordPress Theme Development: How to redirect templates the right way?
- Disable front-page.php template
- Change the template of multiple multisite pages at the same time
- Highlight “Show all” item in wp_list_categories
- create-guten-block in wordpress theme?
- Set a them for all subset of category
- How to show post from category select
- Single page site with history.js
- Category specific themes?
- How can I detect hierarchal relationships beyond children (grandchild, great-grandchild, etc)?
- The default code for “posts_nav_link” on category.php isn’t working
- Move default page templates to sub directory
- How to make permalinks update from code?
- How to set a page as homepage in stead of the newspages?
- Where to place template files?
- Is there any tool to find lines of codes responsible to generate front-end HTML elements?
- How do I get the trackback count of a post in wordpress without writing an SQL query?
- Load sidebar template just once to prevent multiple animations
- Replace single_template filter with what for default posts?
- Need help with adding templates (archives and sitemap) to WordPress child theme
- Template for landing pages
- wordpress 404 not found after rewrtie the author link
- How to seperate static phrases from template files in custom theme?
- Issue On Displaying Pages with Post Name Permalink
- Issue on Getting Custom post type Thumbnail’s URL
- Broken theme, template is missing
- WordPress page/blog incorporated into static website
- How to add menù section to my WordPress template?
- Post and page content not displaying in search results
- Why still output /wp-content/themes/twentynineteen?
- How to get category lists by name or slug
- How to add custom meta box when you have a custom page template file
- Password protect a custom template
- Templates dropdown not appearing using _s theme (underscores)
- Load different single.php templates according to post layout selection
- Confused by the behaviour of “front page” / “home” templates
- Only the latest post shows up on post page?
- the_category() tag not styling HTML or CSS
- I need to develop a one-page design
- add jquery file if a certain page is included
- How to remove permalinks links presents in each page of my site?
- Under theme folder, what’s sequence of action for index.php, page.php, single.php?
- How to custom category template based on category?
- Is there a template tag I can use to link to the archive page corresponding to the month that a post was published on?
- List categories of a post hierarchically?
- If I remove Category base from my URLs, how difficult will rollback be?
- What are the permalinks options for “Category” base and removing it?
- Archives and Categories in Custom Menu
- How to Modify WP_Includes/blocks/latest_posts.php
- How do I open a post in a custom page in wordpress?
- Does single webpage do not need navigation to create a slug in permalink?
- Getting post URL within custom content template
- How to implement pagination in category.php template
- Template for front page (latest posts)
- Using wp_add_inline_style Inside a Template File
- which template should I use for single category post?
- Should I use template files or just use conditional tags in index.php?
- Different templates for each category level
- Child theme in separate WordPress Install
- How to show children pages as array
- Display content on Single page
- Create a variable with string, array or multiple values
- Using require_once for parent-directory not working but is working in sub-directories
- How can I fix the even/odd child classes comments so that the comments are unaffected by the top-level even/odd?
- Problem with multiple menus in theme
- Enable WP to accept standard jQuery code embeding between the tags [duplicate]
- What is the advantage of using home.php over index.php for the front page
- Permalinks problem with custom theme
- How customizable is a self-hosted WordPress blog compared to a Blogger blog?
- Configuring static page with add_rewrite_rule gives 404 after navigating to Permalinks admin panel
- Meaning of “if ( is_home() && ! is_front_page() )” snippet?
- What is the point of using archive.php instead of index.php?
- Theme template file for a specific custom taxonomy