Esempio n. 1
0
 function widget($args, $instance)
 {
     extract($args);
     $title = apply_filters('widget_title', $instance['title']);
     $menu = $instance['menu'];
     echo $before_widget;
     if ($title) {
         echo $before_title . $title . $after_title;
     }
     echo "<ul class='menus-plus-widget' id='menus-plus-" . $menu . "'>";
     if (function_exists('menusplus')) {
         menusplus($menu);
     }
     echo "</ul>";
     echo $after_widget;
 }
Esempio n. 2
0
function newsletter_parts($passed_menu_id = null, $passed_target = 'main')
{
    global $wpdb;
    $items_table = $wpdb->prefix . "menusplus";
    $menus_table = $wpdb->prefix . "menusplus_menus";
    $wpdb->show_errors();
    // Returns the best possible menu_id
    if (!$passed_menu_id) {
        $item = $wpdb->get_row("SELECT * FROM {$menus_table} ORDER BY id ASC", ARRAY_A);
        $menu_id = $item['id'];
    } else {
        $menu_id = $passed_menu_id;
    }
    $items = $wpdb->get_results("SELECT * FROM {$items_table} WHERE menu_id = {$menu_id} ORDER BY list_order ASC", ARRAY_A);
    $last_target = '';
    /*
    	if ( preg_match('/^toc$/', $passed_target) ) :
    	    if (count($items) > 0) :
    		    foreach ($items as $item) :
    
    			    $id = $item['id'];
    			    $wp_id = $item['wp_id'];
    			    $list_order = $item['list_order'];
    			    $type = $item['type'];
    
    			    $class = $item['class'];
    			    $url = $item['url'];
    			    $label = $item['label'];
    			    $children = $item['children'];
    			    $children_order = $item['children_order'];
    			    $children_order_dir = $item['children_order_dir'];
    			    $depth = $item['depth'];
    
                    global $wpdb;
    
                    $postdata = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE ID=$wp_id");
                        
                    echo '<li><a href="#' . $id; . '">' .  $postdata->post_title . '</a></li>';
    
                endforeach;
            endif;
        else:*/
    if (count($items) > 0) {
        foreach ($items as $item) {
            $id = $item['id'];
            $wp_id = $item['wp_id'];
            $list_order = $item['list_order'];
            $type = $item['type'];
            $target = $item['target'];
            if (preg_match('/main|side|toc/', $target)) {
                $last_target = $target;
            } else {
                $target = $last_target;
            }
            $class = $item['class'];
            $url = $item['url'];
            $label = $item['label'];
            $children = $item['children'];
            $children_order = $item['children_order'];
            $children_order_dir = $item['children_order_dir'];
            $depth = $item['depth'];
            $title = $item['title'];
            $siteurl = get_bloginfo('siteurl');
            if ($passed_target) {
                if (preg_match("/{$passed_target}/", $target) || preg_match('/toc/', $passed_target) && !preg_match('/section/', $type)) {
                    if ($type == "section") {
                        echo "\n<h3>{$label}</h3>\n";
                    }
                    if ($type == "page") {
                        $array = array("title_li" => NULL, "include" => $wp_id, "sort_column" => $children_order, "sort_order" => $children_order_dir, "depth" => 1, "echo" => 0);
                        $top = wp_list_pages($array);
                        if ($children == "true" && get_pages("child_of=" . $wp_id)) {
                            echo $top = str_replace("</li>", "", $top);
                            $array = array("title_li" => NULL, "child_of" => $wp_id, "sort_column" => $children_order, "sort_order" => $children_order_dir, "depth" => $depth, "echo" => 0);
                            echo "<ul>";
                            echo $children = wp_list_pages($array);
                            echo "</ul></li>";
                        } else {
                            echo $top;
                        }
                    }
                    if ($type == "post") {
                        global $wpdb;
                        global $post;
                        $menus_table = $wpdb->prefix . "menusplus_menus";
                        $wpdb->show_errors();
                        //$posts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE ID = '$wp_id'", ARRAY_A );
                        $my_posts = array();
                        $my_posts[] = get_post($wp_id);
                        $count = 0;
                        foreach ($my_posts as $post) {
                            setup_postdata($post);
                            if (preg_match('/toc/', $passed_target)) {
                                ?>
                    	<li><a href="#<?php 
                                echo $id;
                                ?>
"><?php 
                                the_title();
                                ?>
</a></li>
                    <?php 
                            } else {
                                echo '<h2 class="' . $class . '"><a name="' . $id . '"></a>';
                                //echo '<a href="' . get_permalink() . '" title="' . $title . '">' . $target . ' - ' . $id . ' - ' . get_the_title() . '</a>';
                                echo '<a href="' . get_permalink() . '" title="' . get_the_title() . '">' . get_the_title() . '</a>';
                                echo '</h2>';
                                the_post_thumbnail(array(160, 151), 'align=right');
                                the_content();
                            }
                        }
                    }
                    if ($type == "cat") {
                        // Identify the current category if we're not on an archive page
                        if (is_single()) {
                            $currCat = get_the_category();
                            $currCatID = $currCat[0]->cat_ID;
                        } else {
                            $currCatID = NULL;
                        }
                        // Deal with the custom attribute title
                        if ($children == "true") {
                            $children = get_categories("child_of={$wp_id}&orderby={$children_order}&hide_empty=0");
                            foreach ($children as $child) {
                                $wp_id .= ", " . $child->cat_ID;
                            }
                        }
                        $array = array("title_li" => NULL, "hide_empty" => 0, "include" => $wp_id, "current_category" => $currCatID, "order" => $childre_order_dir, "orderby" => $children_order, "depth" => $depth);
                        wp_list_categories($array);
                    }
                    if ($type == "url") {
                        echo "<li class=\"{$class}\">";
                        echo "<a href=\"{$url}\" target=\"{$target}\" title=\"{$title}\">{$label}</a>";
                        echo "</li>";
                    }
                    if ($type == "hybrid") {
                        $menu = $wpdb->get_row("SELECT menu_title FROM {$menus_table} WHERE id = {$wp_id}");
                        echo '<li class="' . $class . '"><a href="' . $url . '" title="' . $title . '">' . $menu->menu_title . '</a>';
                        echo "<ul class='children'>";
                        menusplus($wp_id);
                        echo "</ul></li>";
                    }
                }
            }
        }
    }
}