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?
- Custom single template for a specific category
- How to insert a logo in the header?
- 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 does WordPress decide what template to use as frontpage
- How can I get wp_head() as a string instead of echoing it?
- Why does my short code get executed before other content?
- 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?
- How can I see what template parts are being called for rendering the viewable page?
- Add a preview to a WordPress Control Panel
- Add a #hash to the links in my custom menu
- Problems with Layout inherit in theme.json
- How to Handle CSS for Multiple Header header.php Files?
- How to load different CSS in different Header?
- Template tags to display custom post type posts in category template?
- Static Front Page problem
- Returning Variables back into a template
- Can not Remove Archives and Meta from Sidebar
- How to override BuddyPress 3.0 bp-nouveau theme files?
- is_archive() content being shown instead of is_category()
- Setting hero/splash section as a blog post
- Where is the correct place(s) in twentysixteen’s header.php to add a Google webfont?
- How to retrieve an image from a post and display it before excerpt of a post? [duplicate]
- Any tag pagination page (except the 1st page) loads index.php template instead of tag.php
- How do I update WooCommerce template files in my theme? [closed]
- Append HTML to an LI of wp_list_categories
- 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?
- Toggle Sidebar Display
- Add theme templates for child categories into the template hierarchy
- Move theme templates to subfolder without losing page associations
- Where can I access my custom page template?
- Theme development question regarding layouts
- Why are theme templates organized as multiple point of entry PHP files instead of reusing your theme’s index.php?
- WordPress Theme Development: How to redirect templates the right way?
- Disable front-page.php template
- How do I create a custom partial / template?
- Change the template of multiple multisite pages at the same time
- Load child template based on parent
- Possible to make a subdirectory that loops through a single category?
- Highlight “Show all” item in wp_list_categories
- create-guten-block in wordpress theme?
- WordPress custom post type permalink: website.com/post-name/post-id
- Override template file i subfolders
- Single Page theme [closed]
- Set a them for all subset of category
- Apply different Class for each element in a foreach()
- How to show post from category select
- Single page site with history.js
- Do i need to keep all the default WP templates files in a theme?
- Category specific themes?
- filter “inactive” categories from wp_list_categories?
- How can I detect hierarchal relationships beyond children (grandchild, great-grandchild, etc)?
- how to display search term in the template full site editor
- Different templates for different category tags
- The default code for “posts_nav_link” on category.php isn’t working
- Sort wp_query by sum of two meta fields
- How to override p2 breathe theme plugin in content template file?
- Move default page templates to sub directory
- What can I use for small text when converting to WordPress?
- Filter categories used with Custom Structure Permalink
- How to make permalinks update from code?
- Default Permalink Type to Postname
- How to set a page as homepage in stead of the newspages?
- Child theme in separate WordPress Install
- Breaking Categories Up into Individual Divs
- 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
- Show posts from all categories
- 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
- Having some trouble properly displaying Custom Post Types in templates
- Enable WP to accept standard jQuery code embeding between the tags [duplicate]
- Mamp pro permalink issues. Pages keep reverting to index.php
- What is the advantage of using home.php over index.php for the front page
- Best practice to create required pages
- Permalinks problem with custom theme
- How customizable is a self-hosted WordPress blog compared to a Blogger blog?
- What is the point of using the front-page.php template? [closed]
- Permalink Setting Changes From Post Name to Default After Changing The Page Name
- 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
- How to create a template for a post in Query Loop block?
- Twenty Twenty-Four Theme, where to put the personalized CSS style rules?