Sorry, really bad at explaining myself sometimes. Why don’t I start from the beginning.
I have this code:
Posted Under <span class="cat-name">
<?php
$category = get_the_category();
echo $category[0]->cat_name; ?>
I’d like to make sure there’s actually something in $category[0]->cat_name before posting it. So I decided to do an if\isset statement:
<?php
if (isset($category[0]->cat_name)) echo // This is where I'd put the above code. ?>
I’m just not totally sure how to do it, obviously. I know I’d have to escape the quotes, but even then it doesn’t work. Here’s what I’ve tried:
<?php if (isset($category[0]->cat_name))
echo "Posted Under <span class=\"cat-name\">
<?php
$category = get_the_category();
echo $category[0]->cat_name; ?></span>"
?>
But no luck. Any ideas? Is there a better way to achieve this? Thanks in advance.
You can mix HTML and PHP code by spanning the
if()across<?php ... ?>blocks. I’ll use a colon instead of braces for readability.