• Resolved Amie

    (@sunburntkamel)


    the links widget included in widgets.php only works with h2/li themes, which mine is not, nor is fauna, nor a few others. i’m trying to write a replacement widget, but i’m quite the n00b with PHP. i’m getting this error:

    Fatal error: Call to a member function on a non-object in c:... ...wordpresswp-contentthemesdisconnected 1.0.2functions.php on line 24

    here’s my functions.php:

    link

    line 24 starts with $link_cats…

    from googling the error, it looks like $link_cats is undefined.

    that section comes from the codex, so i’m wondering if maybe i need to do something to my widget to make the variable abailable to it? or is there something else broken, and this is just a symptom?

    you can see the error at my test blog

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Amie

    (@sunburntkamel)

    welp, i guess i’ll just recommend people use the links block widget then, since it respects $before_widget and $before_title.

    it would still be nice to solve this, though.

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    The reason your code failed is because you don’t have $wpdb defined. You need to declare it global at the start of the function in order to get access to it. Just stick a “global $wpdb;” at the very beginning of the widget_linkslist() function.

    Other than that, your code is fine, but you do need to stick ul> and /ul>
    tags around the call to wp_get_links(). Why? Because wp_get_links will stick the li> tags around each link. Well, that’s not entirely true, it will use the correct “Before Link”, “Between Link and Description”, and “After Link” settings defined for the Link Categories in the Links Manager, but these are usually li> and such and there’s no reason for most people to ever change them. No themes change them that I’m aware of.

    The better fix for this is in the widget plugin itself. Changing that to use the code similar to the codex linked to above really makes more sense than using get_links_list().

    Thread Starter Amie

    (@sunburntkamel)

    thanks muchly. i thought it might be something like that.
    i’m actually ok with people breaking the functionality by changing the ‘before link’ and ‘after link’ fields.
    it’s always annoyed me that most themes make those fields pointless.

    Thread Starter Amie

    (@sunburntkamel)

    i agree that this should be fixed in widgets.php, it’s bizarre that they would go too such lengths to make the widget format customizable, and then ignore that on the blogroll widget.

    to be bulletproof(er), you’d need to discover whether or not the ‘before link’ and ‘after link’ are set to ‘
    li>’, and if they are, put in ‘ul’ tags, and if not, put in a ‘<div>’

    Thread Starter Amie

    (@sunburntkamel)

    and for the love of god, in a forum where we’re talking about code, there should be a more reliable method of posting code.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Links Widget’ is closed to new replies.