Užitečné pluginy, návody a šablony pro WordPress CMS

Multikriteriální filtrování (vyhledávání) příspěvků

Multiple Category Selection Widget
http://wordpress.org/…tion-widget/

This plugin gives you the ability to provide your users with a widget full of dropdowns based upon parent categories and their sub-categories. You can now set up an AJAX chained select box. For example, if you have multiple countries, and multiple states for each country, you can get a user to select a country. Upon selecting the country, the plugin looks for any states under that country, and then shows the dropdown box for the states under that country beneath the country dropdown.

Multiple subcategories spanning multiple parent categories (though multiple categories inside a single parent cannot be chosen) are chosen and intelligently filter your posts.

Please note that this plugin, while it is a widget, can be used on a sidebar you define anywhere within your theme that you like. Think of it as a 'block' area rather than a 'sidebar'.

Alternativy

WP Ultimate Search
https://wordpress.org/…screenshots/

Powerful AJAX-based search alternative which supports faceting queries by taxonomies, terms, location, and post metadata.

Query Multiple Taxonomies
http://wordpress.org/…-taxonomies/

Say you have two custom taxnomies defined: genre and artist.

Currently, you can do the following types of queries on your site:
?genre=jazz
?genre=jazz&cat=1

But you can't do this:
?genre=jazz&ar­tist=chet-baker

WordPress will just ignore one of the parameters. This plugin fixes that. It also comes with a drill-down navigation widget.

WP Custom Fields Search
http://wordpress.org/…elds-search/

This plugin allows multiple form inputs to be configured to search different aspects of a post including custom fields.
It is designed to filter posts in a more structured way than the default wordpress search. Specifically it allows multiple form inputs to be configured to search different aspects of a post, i.e. one term could search the post content, one the post title and one could search a custom field associated with the post.

The blog admin is able to build a customised search form. It allows you to search by the standard post information and by custom fields and to choose what HTML form elements should be presented for each search field.

Taxonomy Picker
http://wordpress.org/…nomy-picker/

Taxonomy Picker is a widget which you can include in your sidebar to help visitors build complex queries using categories and your custom taxonomies by chosing terms from drop down boxes. The widget also includes a text search making it easy to search for text only within certain categories or taxonomies.
Results will be displayed using your theme's standard search form so the results need no additonal styling.

Demo »

Úpravou kódu (bez pluginů)

Výběr (průnik) z více štítků současně, zaškrtáváním checkboxů v šabloně stránky s filtrem:

<?php if (empty($_POST)): ?>
        <form action="<?php echo bloginfo('url'); ?>/?page_id=xy" method="post" accept-charset="utf-8">
                <div>Filtrování příspěvků podle štítků</div>
                <p>
                <?php
                // list all tags with a checkbox next to them
                $tags = get_terms( 'post_tag' );
                $checkboxes = '';
                foreach($tags as $tag):
                        $checkboxes .='<input type="checkbox" name="tags[]" value="'.$tag -> slug.'" id="tag-'.$tag->term_id.'" /><label for="tag-'.$tag->term_id.'">'.$tag->name.'</label>';
                endforeach;
                print $checkboxes;
                ?>
                </p>
                <p><input type="submit" value="Filtruj"></p>
        </form>

<?php else:

        // If there's a tag search
        if (isset($_POST["tags"])){
                $tags_array = array();
                $tags_array = $_POST["tags"];

                foreach ($tags_array as $key => $value) {
                        //      tag1 AND tag2 is chosen, add a plus after the tags.
                        $string .= $value.'+';
                }
                // Remove the last + symbol in the string
                $tags = substr($string, 0, -1);
        }

        // build the url with the variables
        $url = home_url()."?tag=$tags";

        // redirect to output page
        wp_redirect($url); exit;
endif; ?>

Výběr (průnik) z více kategorií současně, zaškrtáváním checkboxů:

U kategorií je třeba ještě nejprve přidat do functions.php

// List categories with checkboxes
function get_categories_checkboxes( $selected_cats = null ) {
        $all_categories = get_categories();
        $o = '<ul style="margin-left:12px">';
        foreach($all_categories as $key => $cat) {
                if($cat->parent == "0") $o .= __show_category($cat, $selected_cats);
        }
        return $o.'</ul>';
}

function __show_category($cat_object, $selected_cats = null) {
        $checked = "";
        if(!is_null($selected_cats) && is_array($selected_cats)) {
                $checked = (in_array($cat_object->cat_ID, $selected_cats)) ? 'checked="checked"' : "";
        }
        $ou = '<li><label><input ' . $checked .' type="checkbox" name="cats[]" value="'. $cat_object->cat_ID .'" /> ' . $cat_object->cat_name . '</label>';
        $childs = get_categories('parent=' . $cat_object->cat_ID);
        foreach($childs as $key => $cat) {
                $ou .= '<ul style="margin-left:12px">' . __show_category($cat, $selected_cats) . '</ul>';
        }
        $ou .= '</li>';
        return $ou;
}

// get category slug form id
function get_cat_slug($cat_id) {
        $cat_id = (int) $cat_id;
        $category = &get_category($cat_id);
        return $category->slug;
}

a v šabloně stránky s filtrem pak

<?php if (empty($_POST)): ?>

        <form action="<?php echo bloginfo('url'); ?>/?page_id=xy" method="post" accept-charset="utf-8">
                <div>Filtrování příspěvků podle kategorií</div>
                <p>
                <?php

                // list all categories with a checkbox next to them
                echo get_categories_checkboxes();
                ?>
                </p>
                <p><input type="submit" value="Filtruj"></p>
        </form>

<?php else:

                //      If there's a category search
                if (isset($_POST["cats"])){
                        $cats_array = array();
                        $cats_array = $_POST["cats"];

                        foreach ($cats_array as $key => $value) {
                                // cat1 AND cat2 is chosen, add a plus after the cats.
                                $slug = get_cat_slug($value);
                                $string .= $slug.'+';
                        }
                        // Remove the last + symbol in the string
                        $cats = substr($string, 0, -1);
                                        }

                // build the url with the variables
                $url = home_url()."/rubriky/".$cats."/";

                // redirect to output page
                wp_redirect($url); exit;
endif; ?>

This shows 15 posts (total) from categories 3 and 11 and 9

<?php query_posts("showposts=15&offset=0&cat=3,11,9"); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>

List categories with checkboxes »

Filtering Wordpress categories using undocumented hook »

OVX.cz 2003 | Přihlásit se
Bez cookies už dnes těžko provozovat plnohodnotný web. Setrváním zde tudíž vyjadřujete souhlas s jejich používáním. Více informací. | Zavřít.