In this tutorial, we’re going to explore a clever method to selectively target items to add a WordPress query loop badge using custom taxonomies and CSS. This technique is particularly useful when you want to highlight specific items in a loop, such as showcasing verified or featured products, without affecting other items. This approach provides a flexible and powerful solution, allowing for customization and differentiation in your content display. Let’s explore how you can implement this technique effectively.
Prerequisites
Please make sure you have the following installed and activated:
- Advanced Custom Fields (ACF)
- A custom post type, if applicable (e.g., ‘deal’ in the given example)
Creating a Custom Taxonomy with ACF
- Navigate to
ACF > Taxonomies
. - Click on ‘Add New’.
- Name your taxonomy for example ‘Origin’, with ‘Origins’ as the plural label.
- Toggle the “Hierarchical” option.
- Select the relevant post type (e.g., ‘deal’ in the example).
- Click ‘Save Changes’.
Adding Taxonomy Terms
- Navigate to your new taxonomy under the relevant post type (e.g.,
Deals > Origins
). - Add a new term, such as ‘internal’, to categorize your content.
- Click ‘Add New Origin’.
Assigning Taxonomy to Items
- Navigate to the list of your post type (e.g.,
Deals > All Deals
). - Edit an item (e.g., ‘Agency Copilot’).
- In the Origins box, check the ‘internal’ option.
- Click ‘Update’.
Implementing CSS for Targeted Styling
- Navigate to
Customizer > Additional CSS
.
- Inspect your webpage to identify the class added by the taxonomy (e.g., ‘origin-internal’).
- Copy the CSS below to target the class for specific styling. For instance:
.origin-internal { position: relative; } .origin-internal:after { position: absolute; content: ""; width: 20px; height: 20px; background-image: url('path_to_your_image'); background-size: contain; top: 24px; right: 24px; }
- Adjust positioning and styling as needed and publish it.
Applying Taxonomy to Other Items
Repeat the process of assigning the ‘internal’ taxonomy to other items you wish to highlight or differentiate.
Tip: You can assign the taxonomy easily via the “Quick Edit” function.
Additional Links
WordPress Query Loop Badge – Conclusion
This method offers a flexible and creative way to highlight specific items in a WordPress query loop. By using custom taxonomies and CSS, you can easily create distinctive elements like verified badges or featured indicators. This approach can be adapted to various contexts, not just for special deals pages but also for blogs, product showcases, and more. Your imagination is the limit!