如何按类别和标签过滤WordPress结果?

时间:2012-07-12 13:15:14

标签: wordpress filter tags

我创建了一个搜索表单和search.php文件来显示结果。唯一的问题是,我想过滤包括标签而不仅仅是内容和标题。这个过程有没有wordpress功能?

搜索表格代码:

<?php if(is_category(array('general-support','activities','discount-cards','equipment','financial','holidays','medical','respite')) || is_single()){?>

<div style="width:auto; margin:0px 40px 0px 20px;">

    <form role="search" action="<?php bloginfo('siteurl');?>" style="margin:0px; padding:0px;">

        <div>
            <h2>Search for</h2>
            <div><input type="text" name="s" id="s" style="width:100%; padding:5px; border:1px solid #ccc; box-shadow:inset 1px 1px 1px #f0f0f0;" /></div>
            <div><input type="hidden" value="14,16,21,18,20,15,22,19,17" name="cat" id="scat" /></div>
        </div>

    </form>

</div>

<?php } ?>

的search.php

<?php query_posts($query_string . '&showposts=10'); ?>

<?php if (have_posts()) : ?>

    <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>

<?php while (have_posts()) : the_post(); ?>


<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    <div class="entry">

        <!--start.entry-wrapper-->
        <div class="entry-wrapper">

            <!--start.post-thumbnail-->

            <?php if(has_post_thumbnail()){?>

            <div class="post-thumbnail-wrapper">
                <a href="<?php the_permalink();?>">
                    <?php the_post_thumbnail('category-thumb'); ?>
                </a>
            </div>

            <?php } ?>

            <!--end.post-thumbnail-->

            <!--start.post-entry--->
            <div class="post-enry-wrapper">
                <h2><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'udesign' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
                <div class="postmetadata">
                    <?php the_content();?>              
                </div>
            </div>

            <!--end.post-entry-->
            <div class="clear"></div>
        </div>
        <!--end.entry-wrapper-->

    </div>

    <?php if(!is_category() && !is_single()){?>

    <div><?php if(function_exists('kc_add_social_share')) kc_add_social_share(); ?></div>

    <?php }?>

</div>
<div class="addGap"></div>
<?php endwhile; ?>

<div class="clear"></div>

<?php       // Pagination
if(function_exists('wp_pagenavi')) :
    wp_pagenavi();
else : ?>

    <div class="navigation">
    <div class="alignleft"><?php previous_posts_link() ?></div>
    <div class="alignright"><?php next_posts_link() ?></div>
</div>

<?php       endif; ?>

请注意,我不喜欢使用任何插件。

1 个答案:

答案 0 :(得分:0)

假设我理解你的问题,这应该会有所帮助:

http://codex.wordpress.org/Function_Reference/wp_get_post_terms

如果你有多个分类法(不仅仅是标签)并希望将它们合并到一个alpha排序数组中,请告诉我。某处我有一个合并/排序功能。

相关问题