Table of Contents
1. Methods to use WordPress (suitable for newbies in website building)
2. If you are a developer (for HTML/PHP/JS sites)
3. How to deal with static site generators (such as Hugo, Jekyll)
Home CMS Tutorial WordPress How to display posts from specific categories

How to display posts from specific categories

Jul 24, 2025 am 12:47 AM

If you want to display articles with specific categories on the website, you can implement them in different ways: 1. WordPress users can use built-in article blocks, plug-ins or widgets to filter categories and customize styles; 2. Developers can implement classification display through database queries, API interfaces and JavaScript dynamic filtering on the front and back ends, and pay attention to security protection; 3. Static site generators such as Jekyll and Hugo can process classification pages in the construction stage through preset classification mechanisms, without database support, and loading speed is fast. The selection method depends on the platform and technical level used.

Want to show articles in specific categories on your website? This is actually a very common need. For example, you are doing a blog that wants to display content such as "travel" or "food" separately. It is not difficult to implement, but the specific operation depends on what platform or framework you are using.

1. Methods to use WordPress (suitable for newbies in website building)

If you are using WordPress, the easiest way is to implement it through built-in functions or plug-ins:

  • Use the default article page template : You can create a new page, and then select "Article Block" in the page editor to set the filter criteria to a certain category.
  • Use plug-ins : Plugins like WP Show Posts or Posts by Category allow you to display articles flexibly by category, and support options such as sorting and quantity limiting.
  • Custom widgets : Some themes come with a sidebar widget with "Category Article List". You can use it by dragging it to the corresponding area.

In addition, if you want to control the display style, you can also add CSS style yourself, or use the custom style function provided by the plug-in.

2. If you are a developer (for HTML/PHP/JS sites)

For websites you write or projects based on PHP or Node.js, you have to filter them from the data level. The basic idea is:

  • When querying the database, the classification conditions are included, such as adding WHERE category = 'travel' to the SQL statement;
  • If it is front-end rendering, you can pass parameters through the API interface, such as /api/posts?category=food ;
  • The front-end display part can be dynamically filtered using JavaScript, such as clicking the button to switch articles in different categories.

What needs to be paid attention to in this part is the consistency of data structures and interface security issues at the front and back ends. Especially when it is open to filter for users, it is necessary to prevent attacks such as SQL injection.

3. How to deal with static site generators (such as Hugo, Jekyll)

If you are using static site generators, such as Jekyll or Hugo, they also have corresponding classification mechanisms:

  • Jekyll : You can add categories: travel to the article in the _posts folder, and then write a page to loop out the articles under this category.
  • Hugo : It has a special category page template, you only need to visit /categories/travel/ to automatically see all articles belonging to the category.

This type of tool usually has the classification information processed during the construction stage, so it loads quickly and does not require dependence on database queries.


In general, it is not complicated to display articles in specific categories. The key is to look at the platform you use and your technical background. Newbie use WordPress plug-in as fast as developers are more suitable for direct manipulation of code, and static sites also have their own ways. As long as you sort out the logic and choose the right tools, this is not a difficult problem.

The above is the detailed content of How to display posts from specific categories. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

ArtGPT

ArtGPT

AI image generator for creative art from text prompts.

Stock Market GPT

Stock Market GPT

AI powered investment research for smarter decisions

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to troubleshoot WordPress email issues How to troubleshoot WordPress email issues Aug 27, 2025 am 07:44 AM

The problem that WordPress cannot send emails can be solved through the following steps: 1. Confirm whether the function depends on email; 2. Check and configure the SMTP plug-in; 3. Troubleshoot server restrictions; 4. Check spam and email formats. First, clarify the functions that need to be supported by email, such as registration, password reset, etc., and then send them through plug-in tests; if the configuration is correct and still cannot receive messages, you should check the host restrictions or firewall problems; finally ensure that the email content is standardized and set SPF and DKIM records to improve delivery rate.

How to deploy WordPress changes safely How to deploy WordPress changes safely Sep 02, 2025 am 06:38 AM

The core steps to ensure that the online website does not affect the update before going online are: testing environment verification, backing up complete data, phased operations, and checking before going online. 1. Modify the local or test environment, use Local or Docker to build the same environment and test it before going online, use plug-ins such as Duplicator to copy the website and check the front and back-end functions; 2. Back up the database and files in full, and use UpdraftPlus and other plug-ins, FTP to manually download or host-manager snapshots, and test the backup and restore effectiveness; 3. Go online in stages, first update non-core plug-ins and then process themes and functional plug-ins, and finally refresh the cache, observe for a few minutes after each change to confirm that there are no 500 errors or white screens; 4. Optional settings for maintenance pages, use plug-ins to display them

How to set up error logging in WordPress How to set up error logging in WordPress Aug 28, 2025 am 05:15 AM

Enabling WP_DEBUG mode is a key step to troubleshoot WordPress website errors. First, change define('WP_DEBUG',false); to define('WP_DEBUG',true); in wp-config.php to enable debug mode. If you need to record errors instead of displaying them on the page, add define('WP_DEBUG_LOG',true); the error log will be saved in wp-content/debug.log. These settings should be turned off after troubleshooting is completed. Secondly, plug-ins such as WPDebugging or ErrorLogMonitor can be used to simplify management, which provide click-to-start

How to identify slow plugins or themes How to identify slow plugins or themes Sep 01, 2025 am 07:16 AM

To identify plug-ins or themes that slow down WordPress websites, first use performance analysis tools such as GTmetrix, GooglePageSpeedInsights, and QueryMonitor to detect the impact of each component; secondly, check the scripts and style sheets loaded in the browser developer tools to identify unnecessary resources; then troubleshoot by switching the default themes and enabling plug-ins one by one; finally pay attention to the frequency of plug-ins updated and user reviews, and avoid using plug-ins that have not been updated for a long time or are frequently complained about the performance.

How to override parent theme templates in a child theme How to override parent theme templates in a child theme Sep 03, 2025 am 08:56 AM

In WordPress development, the method to safely modify the parent theme template file is to overwrite it through child themes. The first step is to create a file structure in the child theme that is exactly the same as the parent theme template file path. For example, the parent theme has single.php or template-parts/content-single.php, and the child theme also creates files with the same path and file name. 1. Ensure that the path and file names are exactly matched; 2. There is no need to copy all template files, only copy the parts that need to be modified; 3. For topics such as WooCommerce that use template replacement mechanism, you need to confirm whether sub-theme coverage is supported, and store files such as woocommerce/single-p according to the correct path

How to add a forum to your WordPress site? How to add a forum to your WordPress site? Sep 15, 2025 am 02:47 AM

InstallbbPresspluginfromWordPressdashboardtoaddforums.2.Createforumsandorganizetopicsundercategories.3.Customizesettingsandappearanceviathemeorwidgets.4.Enableuserregistrationandencourageengagementthroughmoderationandstarterposts.

How to install WordPress using Softaculous How to install WordPress using Softaculous Sep 16, 2025 am 04:47 AM

Installing WordPress through Softaculous is the easiest and fastest way. 1. Log in to cPanel to find the Softaculous application portal; 2. Enter the installation interface and click "InstallNow"; 3. Fill in the protocol, domain name, directory, database and other information, set the site title and administrator account; 4. After confirming that it is correct, click "Install" to complete the deployment; 5. After the installation is completed, access the backend and front desk through the provided link to check whether it is normal, pay attention to checking the key information such as directories, account passwords, etc. to avoid errors.

How to update WordPress core using WP-CLI How to update WordPress core using WP-CLI Aug 27, 2025 am 05:13 AM

The steps to update WordPress core files using WP-CLI are as follows: 1. Check the current version, execute wpcoreversion to view the current version and use wpcorecheck-update to confirm whether there is any update; 2. It is recommended to back up the database and files before the update, and you can use wpdbexportbackup.sql to export the database; 3. Execute wpcoreupdate to update the core files, or specify the version number to update; 4. Use wpcoreversion to verify the version information after the update is completed; 5. Clean the cache and check the site status, use wpcacheflush to clear the cache, and access the front and backends to ensure no errors and compatibility issues. The whole process is simple and high

See all articles