$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>change read more text in archive page depending on post category|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

change read more text in archive page depending on post category

matteradmin6PV0评论

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?

Share Improve this question asked May 5 at 14:12 ErickErick 112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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 &amp; Strawberries</span>";
} else {
    echo "<span>Fruits</span>";
}

It really works fine for me.

Post a comment

comment list (0)

  1. No comments so far