I’m currently using the following in my single.php file to list the parent category and child category that my posts belong to:
foreach((get_the_category()) as $category) {
echo '<h1>'.$category->cat_name . '</h1>';
}
So this results in:
<h1>Events</h1><h1>News</h1>
However, I would like to store each <h1> value in a separate variable.
So my eventual code could be:
$i1 = "<h1>Events</h1>";
$i2 = "<h1>News</h1>";
How do I do this?
You want to use a “variable variable”:
However, I would just use an array: