WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Links Widget (6 posts)

  1. sunburntkamel
    Member
    Posted 8 years ago #

    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

  2. sunburntkamel
    Member
    Posted 8 years ago #

    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.

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

    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().

  4. sunburntkamel
    Member
    Posted 8 years ago #

    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.

  5. sunburntkamel
    Member
    Posted 8 years ago #

    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>'

  6. sunburntkamel
    Member
    Posted 8 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic