WordPress.org

Ready to get started?Download WordPress

Forums

Asides in Kubrick template cause in_category and array PHP errors? (5 posts)

  1. WCityMike
    Member
    Posted 8 years ago #

    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?

  2. leofish
    Member
    Posted 8 years ago #

    WCityMike

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

  3. WCityMike
    Member
    Posted 8 years ago #

    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.

  4. WCityMike
    Member
    Posted 8 years ago #

    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.

  5. WCityMike
    Member
    Posted 8 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic