• I’m trying to rid up a simple script in my category template that will first check to see if it’s a category page, then check the ID of the category and then parse in a description based on the ID of the category. For whatever reason, I got the first part right, but I can’t get the second part right. I can’t find any pages through google really detailing what I’m doing wrong so I figured I’d ask here.

    <?php if (is_category()) : ?>
    <div class="cat-desc">

    <?php if (single_cat_title() == "General") : ?>
    (This is where the description goes for the General category)
    <?php endif; ?>

    </div>
    <?php endif; ?>

    Where am I going wrong? This “works” but all it does is, instead of displaying the description, it displays the name for the categories.

Viewing 4 replies - 1 through 4 (of 4 total)
  • I’m not sure but single_cat_title is a function, so that will not work. Alternatively you could try the_category_ID(), which according to the template reference is static data.

    Thread Starter amiantos

    (@amiantos)

    Thanks, I’ll try that

    Thread Starter amiantos

    (@amiantos)

    Oh, I don’t think that will work. Anyone else have any tips? It’s got to be possible… some how. I tried assigning the function’s output to a variable and then using the variable in the IF, but that didn’t work either.

    The function already is a constant, eg the_category_ID() is 1 for the category general (if you left it that way).
    Maybe this is easier:
    if ($_GET[‘cat’] == “1”)
    That should work also.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘A quick hand (PHP IF)’ is closed to new replies.