I'm looking for a way to change the read more text on the archive page when posts are in a certain parent category, let's say 'Apple' or 'Strawberry'. Posts in other categories will use the standard text.
On the web i've found a lot of code snippets, but they didn't work out for me. Does anyone have a clue how to solve it?
I'm looking for a way to change the read more text on the archive page when posts are in a certain parent category, let's say 'Apple' or 'Strawberry'. Posts in other categories will use the standard text.
On the web i've found a lot of code snippets, but they didn't work out for me. Does anyone have a clue how to solve it?
With the online php generator I've created this code snippet.
$post_categories = get_the_category($post->ID);
$parent_category_name = '';
if (!empty($post_categories)) {
$parent_category = $post_categories[0]->parent ? get_category($post_categories[0]->parent) : $post_categories[0];
$parent_category_name = $parent_category->name;
}
if ($parent_category_name === 'Apple' || $parent_category_name === 'Strawberry') {
echo "<span>Apples & Strawberries</span>";
} else {
echo "<span>Fruits</span>";
}
It really works fine for me.