WordPress.org

Ready to get started?Download WordPress

Forums

The Loop and widget question (6 posts)

  1. ergate
    Member
    Posted 8 years ago #

    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 http://codex.wordpress.org/Template_Tags/the_author_description
    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.

  2. manstraw
    Member
    Posted 8 years ago #

    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.

  3. Samuel Wood (Otto)
    Tech Ninja
    Posted 8 years ago #

    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:
    $user=get_userdata($someUserId);
    echo "$user->first_name $user->last_name - $user->description";

  4. ergate
    Member
    Posted 8 years ago #

    Otto42:
    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.

    Thanks

  5. manstraw
    Member
    Posted 8 years ago #

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

  6. suleiman
    Member
    Posted 7 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags