Support » Plugins » Asides in Kubrick template cause in_category and array PHP errors?

  • I implemented the Asides code for the Kubrick template as described here:

    http://blog.randomlog.net/archives/2005/01/28/implementing-matts-asides-with-wp-15/

    However, I recently tracked down that it was generating an error every time that an uncategorized post is posted to the Weblog. The errors it generates are:

    Invalid argument supplied for foreach() in /wp-includes/template-functions-category.php on line 410

    in_array(): Wrong datatype for second argument in /wp-includes/template-functions-category.php on line 414

    It is, most definitely, the code that is outlined on the above page; once it was removed (discovered through a period of trial and error), the errors ceased.

    One could argue that it could be avoided by never posting an uncategorized post. However, del.icio.us’ automatic daily posting has a flaw with its category implementation, and thus every daily post of its links gets posted without a category, causing the error to occur on a nightly basis.

    Any ideas what I can alter to get things working again?

Viewing 4 replies - 1 through 4 (of 4 total)
  • WCityMike

    Are you using K2 Beta96. Asides are built in and appear to be working fine.

    Thread Starter wcitymike

    (@wcitymike)

    No, just Kubrick. I’d hate to plunk K2 down in there, considering I’ve customized the heck out of this one just the way I like it.

    Thread Starter wcitymike

    (@wcitymike)

    I should explain that the section of code it seems to choke on is:

    function in_category($category) { // Check if the current post is in the given category
    global $post, $category_cache;
    $cats=array();
    foreach ($category_cache[$post->ID] as $cat) :
    $cats[] = $cat->cat_ID;
    endforeach;
    if ( in_array($category, $cats) )
    return true;
    else
    return false;

    If I add in:

    if ($cats == '')
    return false;

    before the if ( in_array($category, $cats) ) line, then the in_array problem doesn’t crop up [I have no idea why — I simply found that solution in a patch.diff file filed somewhere on mosquito.wordpress.org], but I have no idea how to similarly get rid of the foreach error, and it doesn’t sound like the best patch.

    The asides code I’m using is exactly as illustrated at the link, aside from the category number being 11 on my blog for Asides.

    Thread Starter wcitymike

    (@wcitymike)

    As the community was unfortunately of no help on this either time I posted to the list (although my thanks to leofish for the K2 thought), I thought I would share for future Googlers that Simple Asides implements the solution nearly perfectly for me.

    I had attempted implementing it before and thought it was poorly coded when it made my front page look very weird, but it turns out it was reacting to title-less asides. Once that was solved, it was fine. I ran into a small problem further editing the appearance of entries (specifically, adding a link to print-friendly versions of my entries), but we’ll see how I can get around that later.

    I must admit, I was discouraged to see the utter dearth of replies both times I brought this to this forum (again, leofish excepted). I guess it’s every man for himself around here, huh?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Asides in Kubrick template cause in_category and array PHP errors?’ is closed to new replies.