Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6202975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:50:00+00:00 2026-05-24T04:50:00+00:00

Sorry, really bad at explaining myself sometimes. Why don’t I start from the beginning.

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:50:00+00:00Added an answer on May 24, 2026 at 4:50 am

    You can mix HTML and PHP code by spanning the if() across <?php ... ?> blocks. I’ll use a colon instead of braces for readability.

    <?php
        $category = get_the_category();
        // let's be extra safe
        if (isset($category[0]->cat_name)):
    ?>
        Posted Under <span class="cat-name">
            <?php echo htmlspecialchars($category[0]->cat_name) ?>
        </span>
    <?php endif ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At first sorry for my really bad title! If you have a better title
first of all I am sorry for the bad description, but I really don't
[EDITED - really sorry, the code I quoted was wrong - have changed the
Sorry I'm really bad at regexes, I finally hacked osmething to work in ruby.
Sorry if this is a really basic question but it's been really getting to
Sorry if this sounds like a really stupid question, but I need to make
I'm really new to VSTO so sorry if this is a newbie question. I'm
Sorry, I'm not really sure of the right way to ask this one so
Sorry for the vague title, as I really can't explain this problem succinctly. Basically
I'm really sorry. This must seem like an incredibly stupid question, but unless I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.