• I’m trying to write a plugin for a widget that gives expandable link lists via javascript. The JS itself has worked when implemented directly into the template. This JS uses hides or shows the content – I don’t want to use dropdown forms that can only open in the same window or tab.

    What I want is something that gets the category id dynamically so that I (or anyone else using) don’t have to put a new section into my code when I make a new category of lists. The technique for doing that was taken from here.

    Not only does what I’ve written not work, but it makes all the pages blank, completely kills the site.

    My plugin is as follows:

    <?php
    
    /*
    Plugin Name: Expandable Links
    Version: 0.1
    Plugin URI:
    Description: Creates a widget for expandable links and blogroll.
    Author:
    Author URI: https://www.kristarella.com/
    */
    
    ?>
    
    <script language="javascript" type="text/javascript">
    function $() {
    
    	var elements = new Array();
    
    	for (var i = 0; i < arguments.length; i++) {
    
    		var element = arguments[i];
    
    		if (typeof element == 'string')
    
    			element = document.getElementById(element);
    
    		if (arguments.length == 1)
    
    			return element;
    
    		elements.push(element);
    
    	}
    
    	return elements;
    
    }
    
    function toggleSec(id, toggleid) {
    
    	var obj = $(id);
    
    	var toggle = $(toggleid);
    
    	if (obj.className == 'sechide') {
    
    		obj.className = 'secshow';
    
    		toggle.innerHTML = '  [-]';
    
    	} else {
    
    		obj.className = 'sechide';
    
    		toggle.innerHTML = '  [+]';
    
    	}
    
    }
    
    </script>
    
    <?php
    function widget_expandlinks_init() {
    	if ( !function_exists('register_sidebar_widget') )
    		return;
    }
    
    function widget_expandlinks($args) {
        extract($args);
        	$options	= get_option('widget_links');
    		$title		= $options[$number]['title'];
    		if (empty($options[$number]['title'])) {
    			$title	= __('Links');
    		}
    
    	$cats = get_categories("type=link&orderby=$order&order=$direction&hierarchical=0&exclude=$exclusions&include=$inclusions");
    
    		echo $before_widget; ?>
    			<?php echo $before_title . $title . $after_title; ?>
    <?php
    	if ($cats) {
    		foreach ( (array) $cats as $cat) {
    
    		echo '<h4><a>cat_ID . '', 'toggle-' . $cat->cat_ID . '');"class="toggle">' . $cat->cat_name . '<span id="toggle-' . $cat->cat_ID . '">  [+]</span></a></h4>';
    		echo '<ul class="sechide" id="sec-' . $cat->cat_ID . '">';
    
    		get_links(' . $cat->cat_ID . ', '
    
    <li>', '</li>
    ', '', TRUE, 'name', FALSE,
    TRUE, -1, FALSE, TRUE);
    
    		echo '</ul>
    ';
    		}
    	}
    	else  {
    	if (!$category) {
    		get_links_list(); }
    ?>
            <?php echo $after_widget; ?>
    <?php
    }
    register_sidebar_widget('Expandable Links',
        'widget_expandlinks');
    
    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter kristarella

    (@kristarella)

    I see now that you can’t just stick the js in there… I’ll fix that. Is there anything else that’s wrong with it?

    Thread Starter kristarella

    (@kristarella)

    Really? No one can comment?

    This is the current code, still not working…

    <?php
    
    /*
    Plugin Name: Expandable Links
    Version: 0.1
    Plugin URI: https://www.kristarella.com/blog
    Description: Creates a widget for expandable links and blogroll.
    Author: kristarella
    Author URI: https://www.kristarella.com/
    */
    
    if (!class_exists("ExpandableLinksPlugin")){
    	class ExpadableLinksPlugin {
    		function ExpadableLinksPlugin(){ //constructor
    		}
    	}
    
    } //End Class ExpandableLinksPlugin
    
    if (class_exists("ExpandableLinksPlugin")){
    	$dl_pluginSeries = new ExpandableLinksPlugin();
    }
    
    function addHeaderCode() {
    	if (function_exists('wp_enqueue_script')) {
    		wp_enqueue_script('expandable_script', get_bloginfo('wpurl') . '/wp-content/plugins/ExpandableLinks/toggle.js', array('prototype'), '0.1');
                }
    
    //Actions and Filters
    if (isset($dl_pluginSeries)) {
    	//Actions
    	 add_action('wp_head', array(&$dl_pluginSeries, 'addHeaderCode'), 1);
    	//Filters
    	}
    }
    
    function widget_expandlinks_init() {
    	if ( !function_exists('register_sidebar_widget') )
    		return;
    }
    
    function widget_expandlinks($args) {
        extract($args);
        	$options	= get_option('widget_links');
    		$title		= $options[$number]['title'];
    		if (empty($options[$number]['title'])) {
    			$title	= __('Links');
    		}
    
    	$cats = get_categories("type=link&orderby=$order&order=$direction&hierarchical=0&exclude=$exclusions&include=$inclusions");
    
    		echo $before_widget; ?>
    			<?php echo $before_title . $title . $after_title; ?>
    <?php
    	if ($cats) {
    		foreach ( (array) $cats as $cat) {
    
    		echo '<h4><a href="javascript:toggleSec('sec-' . $cat->cat_ID . '', 'toggle-' . $cat->cat_ID . '');"class="toggle">' . $cat->cat_name . '<span id="toggle-' . $cat->cat_ID . '">  [+]</span></a></h4>';
    		echo '<ul class="sechide" id="sec-' . $cat->cat_ID . '">';
    
    		get_links(' . $cat->cat_ID . ', '<li>', '</li>', '', TRUE, 'name', FALSE,
    TRUE, -1, FALSE, TRUE);
    
    		echo '</ul>';
    		}
    	}
    	else  {
    		if (!$category) {
    			get_links_list();
    		}
    	}
    ?>
            <?php echo $after_widget; ?>
    <?php
    }
    register_sidebar_widget('Expandable Links',
        'widget_expandlinks');
    
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can’t get links plugin to work’ is closed to new replies.