Forums

Trouble with deprecated get_the_category (5 posts)

  1. monkeywrench
    Member
    Posted 8 years ago #

    Just upgraded to 1.5 and everything has gone fine so far except for one little problem.

    I have been changing the width of a div depending on the id number of the current post. Under 1.2, I used this:

    <?php foreach(get_the_category() as $cat){}; ?>

    to get the ID number, and then performed a simple If:

    if ($single) {
    if ($cat->category_id == 26) {

    to branch accordingly. With get_the_category deprecated, I'm stumped as to how to replicate this functionality. The codex listed a block of code that was supposed to work as a substitute, but it generates an error when I try to use it. Please help!

    Thanks

  2. Kafkaesqui

    Posted 8 years ago #

    get_the_category() is deprecated?

  3. monkeywrench
    Member
    Posted 8 years ago #

    whoops, sorry, my mistake. I'm looking at too many versions of things. the_category_id was deprecated, so I replaced it a while ago with

    <?php foreach((get_the_category()) as $cat) { echo $cat->category_id . ' '; } ?>

    Now I've gone stupid and forgotten what was depracted and what works and what doesn't.

    Anyway, after the upgrade to 1.5, that line now generates this error:

    Invalid argument supplied for foreach()

    So that's actually the problem that I need to fix.

  4. Kafkaesqui

    Posted 8 years ago #

    It would have to run in The Loop (much like the_category_ID() would have to). Is that where you have it? I ask because I run similar code in my templates with no problems.

  5. monkeywrench
    Member
    Posted 8 years ago #

    Rats. That must be the problem. Looks like that means I'm gonna have to re-structure some things from the way the loop worked in 1.2.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.