Support » Plugins » The Loop and widget question

  • I have made a widget that displays the Author Description using the The_Author_Description tag. The widget works fine, but a recent question was brought up and I do not know the answer. In the codex when describing this tag it says

    This tag must be used within The Loop.

    from here
    How will (can) this affect The Author Description widget I have made. So far in testing I have not had any problems, but I thought I would check before I make a formal announcement.

Viewing 5 replies - 1 through 5 (of 5 total)
  • if it’s ok in testing, perhaps it’s ok. I don’t think anyone can comment on this without knowing more, and perhaps seeing your source code. I would recommend you test it against other widgets/plugins that also use The_Author_Description tag and see if they co-exist.

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    the_author_description() must be used in the loop because it’s retriving data that is set by the process of pulling a post to display. All these “loop only” functions do this. That’s why they’re loop only.

    The Loop is essentially going through a bunch of posts (whatever posts it’s displaying on the page) and setting these global variables. Then the Loop-Only functions display these variables when you want them to.

    In your particular case, you’re seeing it work for one reason only: The sidebar you’re displaying it in happens to occur after the loop in your theme. So the data you see is the data that was set by the last post in your loop.

    Your widget will be broken on a number of pages:
    -Blogs with more than one poster
    -Themes that have the sidebars come first in the page structure
    -Pages that don’t contain any posts (search results, etc)

    My suggestion is not to use the_author_description() for whatever you’re doing. You should use get_userdata() or get_userdatabylogin() to get back an array of info about the user you’re interested in instead, and then display that. Something sorta like this:
    echo "$user->first_name $user->last_name - $user->description";

    Ok, that explains the errors I started to have trying to implement this in different installs.

    And thanks for the suggestion, it answered my next question before I could ask it.

    In the near future I am going to try and fix these problems, and I will probably fudge things up and need post back for more help.


    um, yeah, widget means sidebar, doesn’t it. thanks otto42 for realising the obvious. I’m going back under my rock …

    is there any way to use the above code but dynamically generate the user_ID from the blog? I desparately need a way to do that!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘The Loop and widget question’ is closed to new replies.