• Resolved LostInNetwork

    (@lostinnetwork)


    The JS Toggle Boxes plugin https://aranea.zuavra.net/index.php/19/ is a very useful feature. I’m currently trying to insert it in widgets.php The link lists are causing some trouble, though. I can see all the relevant ids and classes and all in page source, but it seems as if the function calls to JSTB_box_toggle and JSTB_box_init would never be carried out. The [+/-] never appear. I have never written php/js before, so I would very much appreciate some help. I have places the required function call to my themes header.php

    CODE:

    function widget_links($args) {

    global $wpdb;

    // Get a list of link categories
    echo “< ul >”;
    $link_cats = $wpdb->get_results(“SELECT cat_id, cat_name FROM $wpdb->linkcategories”);

    // Loop through all categories, print cat.headers and [+/-]
    foreach ($link_cats as $link_cat) {
    $cat_id = $link_cat->cat_id;
    echo ‘< li id=”linkcat-‘.$cat_id.'” >’;
    echo ‘< h2 >’.$link_cat->cat_name.'< /h2 >’;
    function_exists(‘JSTB_box_toggle’)? JSTB_box_toggle(‘[+/-]’, ‘toggle’, ‘Click to toggle’, ‘cookie_link_’ . $cat_id, ‘link_list_’ . $cat_id) :”;

    // Sublist: Links in current category
    echo ‘< ul id=”link_list_’.$cat_id.'” class=”JSTB_shown” >’;
    wp_get_links($link_cat->cat_id);
    echo “< /ul >”;

    function_exists(‘JSTB_box_init’)? JSTB_box_init(‘cookie_link_’.$cat_id, ‘JSTB_shown’, ‘link_list_’.$cat_id) :”;

    echo “< /li >”;
    }

    echo “< /ul >”;
    }

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter LostInNetwork

    (@lostinnetwork)

    Note: In the code above, I have inserted some spaces inside the UL and LI tags, so that they would display as plain code.

    Thread Starter LostInNetwork

    (@lostinnetwork)

    Note: In the code above, I have inserted some spaces inside the UL and LI tags, so that they would display as plain code.

    Thread Starter LostInNetwork

    (@lostinnetwork)

    Solved. The following code works:

    Edited widget_links function in widgets.php version 1.0.20060711

    Tested on WordPress 2.0.7

    function widget_links($args) {
    extract($args);
    global $wpdb;
    ?>

    <?php
    echo “$before_widget”;
    echo “< ul >”;

    // Loop through all link categories
    $link_cats = $wpdb->get_results(“SELECT cat_id, cat_name FROM $wpdb->linkcategories”);
    foreach ($link_cats as $link_cat) {

    // Set current link category id
    $cat_id = $link_cat->cat_id;

    // Create a new

    • element in the list of link categories.
      echo ‘< li id=”linkcat-‘.$cat_id.'”>’;
    • // This new list element begins with a title
      echo $before_title;
      echo ”.$link_cat->cat_name.’ ‘;

      // and the expand/collapse link
      echo function_exists(‘JSTB_box_toggle’)? JSTB_box_toggle(‘[+/-]’, ‘toggle’, ‘Click to toggle’, ‘cookie_link_’.$cat_id, ‘toggle_link_’.$cat_id) :”;
      echo $after_title;

      // followed by a list of links
      echo ‘< ul id=”toggle_link_’.$cat_id.'” class=”JSTB_shown”>’;
      wp_get_links($link_cat->cat_id);
      echo “< /ul >”;

      // Initialize
      echo function_exists(‘JSTB_box_init’)? JSTB_box_init(‘cookie_link_’.$cat_id, ‘JSTB_shown’, ‘toggle_link_’.$cat_id) :”;
      // and this particular category of links is done
      echo “< /li >”;

      // Next round in loop begins
      }

      // All link categories done.
      echo “< /ul >”;
      echo “$after_widget”;
      ?>

      <?php
      }

    Thread Starter LostInNetwork

    (@lostinnetwork)

    In the code above, extra spaces have been applied around UL and LI elements so that they would be visible in this post.

    There is an extra line feed in the middle of the code, because I forgot to “disable” one < LI > element in the middle of a comment line.

    Problem solved.

    Next time post code
    as text (.txt) on your site or
    at https://wordpress.pastebin.ca

    Thread Starter LostInNetwork

    (@lostinnetwork)

    Thanks. I will do that. I don’t have a site of my own, so that pastebin will be usefull. I’ll use it next time.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Also, next time, don’t edit the widgets plugin. Just create a new widget of your own, with a different name, in a different plugin. Then you can distribute the plugin more easily.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Implementing JS Toggle Boxes for the widgets widget works plugins’ is closed to new replies.