How to Display Item Categories in Feedzy WordPress Plugin
As a WordPress site owner, you may be using the popular Feedzy RSS Feed Aggregator plugin to pull in content from various sources and display it on your website. One common request from users is the ability to show the category information for each feed item alongside the title, description, and other metadata.
Fortunately, Feedzy provides a handy filter that allows you to customize the item data that is displayed. In this blog post, we'll walk you through the steps to add the category information to your Feedzy feed items.
What is Feedzy?
Feedzy is a powerful WordPress plugin that makes it easy to aggregate content from RSS feeds and display it on your website. Some of the key features of Feedzy include:
- Multiple Feed Sources: You can add multiple RSS feeds from different sources and have Feedzy display the combined content.
- Customizable Layouts: Feedzy offers various layout options to display your feed items, including grids, lists, and carousels.
- Caching: Feedzy caches the feed content to improve page load times and reduce server load.
- SEO Optimization: Feedzy includes features to optimize the feed content for better search engine visibility.
One of the common requests from Feedzy users is the ability to display the category information for each feed item. This can be particularly useful if your feed sources include content from various categories, and you want to give your users an easy way to understand the context of each item.
Adding Category Information to Feedzy Items
Fortunately, Feedzy provides a handy filter that allows you to modify the item data that is displayed. The feedzy_item_filter
filter allows you to add, remove, or modify the information that is displayed for each feed item.
Here's the code you can add to your theme's functions.php
file to display the category information for each Feedzy item:
add_filter( 'feedzy_item_filter', 'add_feedzy_item_category', 20, 2 );
function add_feedzy_item_category( $itemArray, $item ) {
if ( $category = $item->get_category() )
if( $category->get_term() )
$itemArray['item_meta'] .= '<br><strong>Category: ' . $category->get_term() . '</strong>';
return $itemArray;
}
Here's how this code works:
- The
add_filter()
function adds the add_feedzy_item_category()
function as a filter for the feedzy_item_filter
hook.
- The
add_feedzy_item_category()
function takes two parameters: $itemArray
(the array of item data) and $item
(the feed item object).
- The function checks if the feed item has a category associated with it using the
$item->get_category()
method.
- If a category is found, the function retrieves the category term using the
$category->get_term()
method and appends it to the item_meta
key in the $itemArray
.
- Finally, the function returns the modified
$itemArray
with the category information added.
Once you've added this code to your theme's functions.php
file, any Feedzy feed items that have category information will display the category alongside the other item metadata.
Customizing the Category Display
The code above will display the category information in a simple format, with the label "Category:" followed by the category term. If you want to customize the way the category is displayed, you can modify the code accordingly.
For example, you could change the label to something more descriptive, or you could display the category using a different HTML element or style. Here's an example of how you could modify the code to display the category in a different format:
add_filter( 'feedzy_item_filter', 'add_feedzy_item_category', 20, 2 );
function add_feedzy_item_category( $itemArray, $item ) {
if ( $category = $item->get_category() )
if( $category->get_term() )
$itemArray['item_meta'] .= '<span class="feedzy-category">Category: ' . $category->get_term() . '</span>';
return $itemArray;
}
In this modified code, we've wrapped the category information in a <span>
element with a class of feedzy-category
. You can then use CSS to style the category information as desired, for example:
.feedzy-category {
font-size: 0.8em;
font-style: italic;
color: #666;
}
This will display the category information in a smaller font size, italicized, and in a slightly darker color than the rest of the item metadata.
Displaying Multiple Categories
If a feed item has multiple categories associated with it, you may want to display all of them. To do this, you can modify the code to loop through the categories and display them all:
add_filter( 'feedzy_item_filter', 'add_feedzy_item_category', 20, 2 );
function add_feedzy_item_category( $itemArray, $item ) {
$category_string = '';
if ( $categories = $item->get_categories() ) {
foreach ( $categories as $category ) {
$category_string .= '<span class="feedzy-category">Category: ' . $category->get_term() . '</span><br>';
}
$itemArray['item_meta'] .= $category_string;
}
return $itemArray;
}
In this modified code, we first check if the feed item has any categories associated with it using the $item->get_categories()
method. If there are categories, we loop through them and build a string of category information, with each category displayed in a separate <span>
element.
Finally, we append the category string to the item_meta
key in the $itemArray
. This will display all of the categories for the feed item, separated by a line break.
Conclusion
In this blog post, we've shown you how to easily add the category information to your Feedzy feed items using the feedzy_item_filter
hook. By following the steps outlined above, you can customize the way the category information is displayed, making it more informative and visually appealing for your users.
If you have any questions or need further assistance, feel free to reach out to the Flowpoint.ai team. We're always happy to help with your WordPress and web analytics needs.
Get a Free AI Website Audit
Automatically identify UX and content issues affecting your conversion rates with Flowpoint's comprehensive AI-driven website audit.