Based on WordPress template hierarchy, categories are displayed using the category.php
template. So in other to display your preferred category, you’ll need to create a category.php
file, and use the query below:
$cat_query = new WP_Query(
array(
'post_type' => 'post',
'cat' => $cat, //WordPress global for getting the current category
'posts_per_page' => 5,
)
);
And then you loop like so:
if( $cat_query->have_posts() ) : while( $cat_query->have_posts() ): $cat_query->the_post();
Related Posts:
- How can I send an email using PHP?
- Modify previous and next text from pagination links
- Shortcode putting html such as
- Load post content into iframe
- Editor role cannot save custom theme options
- Does WordPress cache get_user_meta() results?
- wp_customize_image_control default value
- WordPress widget in custom theme
- Specific Loop For 2 Within Each
- POSTS list in WordPress by views
- Anything I can add to functions.php to make text widgets accept PHP?
- What’s the proper way to use wp_enqueue_script/style?
- Print number of post (in reverse)
- After upgrading to PHP 7.0 my contact form outputs error
- Count number of published posts by type
- Can’t increase posts_per_page by variable
- Use WordPress’s Media Uploader/ Manager in non WordPress php application
- Get/Set wp.customize.previewer.previewUrl
- Can A Shortcode Get HTML/Text From Content And Return It Twice With Added HTML?
- Why is ‘admin’ missing from my admin links?
- How to check If Oembed is empty or not
- How do I access the media settings
- Set post title based on first h2 element in the content section
- Custom field value not saving when it contains a URL?
- Do changes to WordPress permalink custom structure affect old urls?
- How do I let users upload files to a chosen location?
- Adding hreflang tags automatically in WordPress subdirectory multisite
- Wp-login appears White Screen, Error: Cannot modify header information
- Set WP_query ‘order’ option by another tables value
- Creating user status mode in WordPress
- Need Help Fixing My Iframes [closed]
- Implementing update_user_meta
- Show when user is online/offline in real time on user_profile.php
- How to add different text in each result of foreach?
- how to update and display an option without reloading the page
- Change “en-US” to “en”
- multiple where condition in result query
- Remove the last X characters of a custom field value
- Featured or last post with a different WordPress style without plugin
- Notify users only on post publish
- Writing PHP code in pages without issue?
- Echo a shortcode div after every 3 posts
- Fix error Gravatar alt
- Code snippet to show current php version inside “At a Glance” box in admin
- getting url from variable that calls picture of current page, not working. Only displays everything instead of url
- str_replace with the_content is not working
- WordPress yoast seo plugin – parse snippet var in meta description
- Make textarea required. Help [closed]
- Different SMTP based on domain
- How to Update an old theme for the latest wordpress version
- How to edit the styles for the table of pages/post listed in the admin when you click on pages/posts?
- How can I use custom menus with a Bootstrap WordPress theme?
- How to track who has deleted files
- foreach repeat html structure after every nth for attachment [closed]
- how to show images without passing it to timthumb.php file for resizing
- Make separate text boxes for separate WordPress Custom Fields
- How to redirect outgoing links via my own website
- How to implement __() function in my theme’s php file?
- remove values within an array user meta
- In PHP how do I make my navigation bar show certain links to admins only?
- Get current user id in function php
- Proper way to remove html code on child theme
- How to pass parameters in wordpress shortcode?
- how to get data from two different table from wordpress database
- Display a custom name when the user has no name settle in his account
- Why can’t I connect to the wordpress install page with Nginx?
- Discount in the specific product title using keyword ( Woocoommerce )
- Can’t make lazy load for my site, help!
- WordPress generates weird permalinks
- WordPress search query, how to modify the sql
- Make a full-width wordpress page
- Modify post image in full size
- Javascript / PHP – closing the loop
- How to link all featured images to custom url in single.php for only non-logged-in users?
- Update an additional user meta field with a string
- number of posts with “Load More”
- Call custom JS function from PHP
- Putting hyperlinked and non-hyperlinked text in one line, centered, on .php [closed]
- Need Quick Help With Product Category Page
- how to remove replicating a tag inside loop?
- My query keeps looping infinitely ! how to stop it?
- blank page when trying to change upload directory
- how to use php in custom toolbar form
- Why isn’t my link attribute getting my css?
- Retrieve first image url from custom post with pagination
- AJAX with Selectbox Plugins (Select2, Chosen, Selectize)
- Difference in Get Variable Location
- Get current WordPress page then add #post ID to the end
- How to set up and use a custom upload directory for post type ‘product’
- WooCommerce Orders pagination
- Import and use a variable in additional settings of Contact Form 7 [closed]
- New to WordPress & Freelancing [closed]
- Add a “Next Post” & “Previous Post” styled button manually to a post
- How to store the_post_thumbnail() value in a variable
- Use HTML Form Data in PHP Function – WordPress Admin Page
- advanced custom fields: repeater field within conditional statement [closed]
- please on skin.php on theme wordpress option fix on theme option to not print empty variables and empty
- How to pass value to add_filter wpcf7_form_tag from another function?
- Custom nav with bootstrap dropdown