Ejemplo n.º 1
0
    /**
     * Front-end display of widget.
     *
     * @see WP_Widget::widget()
     *
     * @param array $args     Widget arguments.
     * @param array $instance Saved values from database.
     */
    function widget($args, $instance)
    {
        global $term;
        $instance = wp_parse_args((array) $instance, $this->defaults);
        $home_url = null;
        $child_of = 0;
        $parent_id = 0;
        if ($instance["top_only"]) {
            $current = false;
        } else {
            $current = get_term_by('slug', $term, 'advert_category');
        }
        if ($current !== false) {
            $child_of = $current->term_id;
            $parent_id = $current->parent;
        }
        include_once ADVERTS_PATH . '/includes/class-html.php';
        if ($parent_id) {
            $parent = get_term_by('term_id', $parent_id, 'advert_category');
            $link = get_term_link($parent);
            $home_url = Adverts_Html::build("a", array("href" => $link, 'title' => $parent->name), sprintf(__("Go Up (%s)", "adverts"), $parent->name));
        } else {
            if ($current !== false) {
                $home_url = Adverts_Html::build("a", array("href" => site_url()), __("Go Up (Home)", "adverts"));
            }
        }
        extract($args, EXTR_SKIP);
        $terms = get_terms('advert_category', array('hide_empty' => (int) $instance['hide_empty'], 'parent' => $child_of));
        wp_enqueue_style('adverts-frontend');
        wp_enqueue_style('adverts-icons');
        echo $before_widget;
        $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
        if (!empty($title)) {
            echo $before_title . $title . $after_title;
        }
        // WIDGET CODE GOES HERE
        ?>
        <div class="wpjb adverts-widget adverts-widget-categories">
            <div class="adverts-grid adverts-grid-compact">
                <?php 
        if ($home_url) {
            ?>
                <div class="adverts-grid-row">
                    <div class="adverts-col-100">
                        <span class="adverts-widget-grid-link">
                            <em><?php 
            echo $home_url;
            ?>
</em>
                            <span class="adverts-icon-up-open" style="vertical-align: middle"></span>
                        </span>
                    </div>
                </div>
                <?php 
        }
        ?>
                <?php 
        if (!empty($terms)) {
            ?>
                <?php 
            foreach ($terms as $term_item) {
                ?>
                <?php 
                $icon = adverts_taxonomy_get("advert_category", $term_item->term_id, "advert_category_icon", "folder");
                ?>
                <div class="adverts-grid-row">
                    <div class="adverts-col-100">
                        <span class="adverts-widget-grid-link <?php 
                echo "adverts-icon-" . $icon;
                ?>
">
                            <a href="<?php 
                esc_attr_e(get_term_link($term_item));
                ?>
"><?php 
                esc_html_e($term_item->name);
                ?>
</a>
                            <?php 
                if ($instance['show_count']) {
                    ?>
                            (<?php 
                    echo adverts_category_post_count($term_item);
                    ?>
)
                            <?php 
                }
                ?>
                        </span>
                    </div>
                </div>
                <?php 
            }
            ?>
                <?php 
        } else {
            ?>
                <div class="adverts-grid-row">
                    <div class="adverts-col-100">
                        <span><?php 
            _e("No categories found.", "adverts");
            ?>
</span>
                    </div>
                </div>
                <?php 
        }
        ?>
 
            </div>
        </div>
        <?php 
        echo $after_widget;
    }
Ejemplo n.º 2
0
<?php

if (!empty($terms)) {
    ?>
<div class="adverts-flexbox adverts-categories-all">
<?php 
    foreach ($terms as $term) {
        ?>
    <?php 
        $icon = adverts_taxonomy_get("advert_category", $term->term_id, "advert_category_icon", "folder");
        ?>
    <?php 
        $count = adverts_category_post_count($term);
        ?>
    <div class="adverts-flexbox-item <?php 
        echo $columns;
        ?>
 <?php 
        echo "adverts-category-slug-" . $term->slug;
        ?>
">
        <span class="adverts-flexbox-wrap">
            <span class="adverts-category-all-main">
                <span class="adverts-icon-<?php 
        esc_html_e($icon);
        ?>
"></span>
                <a class="" href="<?php 
        esc_attr_e(get_term_link($term));
        ?>
">
Ejemplo n.º 3
0
/**
 * Displays meta fields on Adverts Category edit page.
 * 
 * This function renders form responsible for displaying box with avaiable
 * category icons and maybe some other category meta data.
 * 
 * @param type $tag
 * @since 0.3
 * @return void
 */
function adverts_category_form_fields($tag)
{
    wp_enqueue_style('adverts-admin');
    wp_enqueue_style('adverts-icons');
    wp_enqueue_style('wp-color-picker');
    wp_enqueue_script('wp-color-picker');
    $icons = array("");
    $file = file(ADVERTS_PATH . '/assets/css/adverts-glyphs.css');
    foreach ($file as $line) {
        if (stripos($line, ".adverts-icon-") === 0) {
            $l = explode(":", $line);
            $icons[] = str_replace(".adverts-icon-", "", $l[0]);
        }
    }
    $current_icon = adverts_taxonomy_get($tag->taxonomy, $tag->term_id, 'advert_category_icon', '');
    ?>

<script type="text/javascript">
(function( $ ) {
 
    // Add Color Picker to all inputs that have 'color-field' class
    $(function() {
        $('.color-field').wpColorPicker();
        $(".adverts-image-icon-picker a").click(function(e) {
            e.preventDefault();
            $(".adverts-image-icon-picker a").addClass("button-secondary").removeClass("button-primary");
            $(this).removeClass("button-secondary").addClass("button-primary").blur();
            $("#advert_category_icon").val($(this).data("name"));
            
        });
        
        $("#adverts-category-icon-filter").keyup(function(e) {
            var val = $.trim($(this).val());
            
            if(val.length > 0) {
                $(".adverts-image-icon-picker > li").hide();
                $(".adverts-image-icon-picker > li[data-name*='"+val+"']").show();
            } else {
                $(".adverts-image-icon-picker > li").show();
            }

            
        });
        
        var scrollTo = $(".adverts-image-icon-picker .button-primary");
        var scrollWrap = $(".adverts-image-icon-picker");

        scrollWrap.scrollTop(scrollTo.offset().top - scrollWrap.offset().top + scrollWrap.scrollTop() - 20);
    });
     
})( jQuery );
</script>
    <tr class="form-field">
        <th scope="row" valign="top"><label for="advert_category_icon"><?php 
    _e("Category Icon", "adverts");
    ?>
</label></th>
        <td>
            <input type="hidden" name="advert_category_icon" id="advert_category_icon" value="<?php 
    esc_attr_e($current_icon);
    ?>
" />
            <input type="text" autocomplete="off" id="adverts-category-icon-filter" placeholder="<?php 
    _e("Filter Icons ...", "adverts");
    ?>
" />
            <ul class="adverts-image-icon-picker">
                <?php 
    foreach ($icons as $icon) {
        ?>
                <?php 
        $title = ucfirst(str_replace("-", " ", $icon));
        ?>
                <li data-name="<?php 
        esc_html_e($icon);
        ?>
">
                    <a href="#" class="<?php 
        echo $icon == $current_icon ? 'button-primary' : 'button-secondary';
        ?>
" title="<?php 
        esc_html_e($title);
        ?>
" data-name="<?php 
        esc_html_e($icon);
        ?>
">
                        <span class="adverts-icon-<?php 
        esc_html_e($icon);
        ?>
"></span>
                    </a>
                </li>
                <?php 
    }
    ?>
            </ul>
            
        </td>
    </tr>

    <?php 
}