Php WordPress:使用过滤器在加载时显示特定类别

Php WordPress:使用过滤器在加载时显示特定类别,php,jquery,wordpress,wordpress-theming,Php,Jquery,Wordpress,Wordpress Theming,我有一个主题和一个公文包,它使用过滤器(所有、新、旧)来显示类别。然而,在加载时,我希望特定(“新”)类别是显示的唯一类别 然后,如果用户希望看到过去的产品,他们会单击“旧”等等 请记住,我将创建另一个公文包,该公文包的新项目将仅在第一次加载时显示 我试图找到答案已经好几个小时了,但我还没有找到 以下是portfolio php页面的代码: <?php /** * Taxonomy Template for the Portfolios */ ?&

我有一个主题和一个公文包,它使用过滤器(所有、新、旧)来显示类别。然而,在加载时,我希望特定(“新”)类别是显示的唯一类别

然后,如果用户希望看到过去的产品,他们会单击“旧”等等

请记住,我将创建另一个公文包,该公文包的新项目将仅在第一次加载时显示

我试图找到答案已经好几个小时了,但我还没有找到

以下是portfolio php页面的代码:

    <?php
    /**
     * Taxonomy Template for the Portfolios
    */
    ?>
    <?php get_header(); ?>

    <?php

    if ( $post ) :

    $port = wp_get_post_terms( $post->ID, array('portfolios') );
    $portfolio = $port[0];

    $post_img_width = "";
    $post_img_height = "";

    global $mav_data; // fetch options stored in $mav_data

    $portfolio_order_1 = $mav_data['portfolio_order_1']; // date, title
    $portfolio_order_2 = $mav_data['portfolio_order_2']; // ASC, DESC

    $tax_query[] = array(
        //'taxonomy' => $wp_query->query_vars['taxonomy'],
        'taxonomy' => 'portfolios',
        'field' => 'slug',
        'terms' => array( $portfolio->slug )
    );

    $args = array(
        'post_type'=> 'project',
        'posts_per_page'=> -1,
        'orderby' => $portfolio_order_1,
        'order' => $portfolio_order_2,
        'tax_query' => $tax_query
    );

    $port_query = new WP_Query($args);

    ?>

    <?php
    $tag_extra_fields = get_option('portfolios_fields');
    $portfolio_layout = $tag_extra_fields[$portfolio->term_id]['_portfolio_layout'];
    ?>
    <section id="content" class="portfolio one-column <?php echo esc_attr( $portfolio_layout ); ?>" role="main">

        <div class="wrapper clearfix">

        <header class="page-header">

            <h1 class="entry-title"><?php echo( $portfolio->name ); ?></h1>

            <?php if ($portfolio->description) { ?><p class="portfolio-header-description"><?php echo( $portfolio->description ); ?></p><?php } ?>

            <?php

            $temp = array();

            foreach ( $posts as $post ) {

                $temp_args = array();

                while ($port_query->have_posts()) : $port_query->the_post(); // the loop begins, we need it here. It's important!!

                $temp_cats = wp_get_object_terms( $post->ID, 'project_category'/*, $args*/ );

                if ( $temp_cats ) {
                    foreach ( $temp_cats as $temp_cat ) {
                        if ( ! in_array( $temp_cat->slug, $temp ) ) {
                            $temp[] = $temp_cat->slug;
                            $categories[] = $temp_cat;
                        }
                    }
                }

                endwhile;

            }

            // DAHEX
            $temp = array();

            if(!empty($categories)) {
                foreach ( $categories as $category ) {
                    $temp[] = array ('term_id'=>$category->term_id,'name'=>$category->name,'slug'=>$category->slug,'term_group'=>$category->term_group,'term_taxonomy_id'=>$category->term_taxonomy_id,'taxonomy'=>$category->taxonomy,'description'=> $category->description,'parent'=>$category->parent,'count'=> $category->count);
                }
            }

            usort($temp, array(new Sorter('slug'), 'sort')); // Sorting Array by slug

            $categories = array();
            foreach ( $temp as $category ){
                $categories[] =(object) $category;
            }
            // DAHEX

            if(!empty($categories)) {

                if(!is_wp_error( $categories )){

                    echo( '<ul id="filters" class="option-set">
                    <li><a href="#" data-filter="*" class="show-all selected">All</a></li>' );

                    foreach ( $categories as $category ) {
                        echo '<li><span class="sep">/</span><a href="#' . $category->slug . '" data-filter=".' . $category->slug . '">' . $category->name . '</a></li>';
                    }

                    echo( '</ul> <!-- /end #filters -->' );

                } else {
                    echo '<span class="ooops">';
                    _e( 'Ooops! nothing found...', 'mav_framework' );
                    echo '</span>';
                }
            }
            ?>
        </header> <!-- /end .page-header -->

        <section id="projects">

            <?php
            while ($port_query->have_posts()) : $port_query->the_post(); // the loop begins
            $terms = get_the_terms( get_the_ID(), 'project_category' );
            $terms = $terms == false ? array() : $terms;
            ?>

            <?php
            $custom = get_post_custom($post->ID);

            $portfolio_permalink = $custom["project_permalink"][0];
            $portfolio_desc = $custom["project_desc"][0];

            if ( !isset( $lightbox_path ) ) {
                $lightbox_path = '';
            }

            // Prepare Project Image Thumb
            $project_img = $custom["project_img"][0];
            $project_img_ID = $custom['project_img_ID'][0];

            // Need some proof check to ensure that no "notice" is thrown ...
            if ( ! empty( $portfolio ) ) {

                $term_slug = $portfolio->slug;

                if ( isset( $custom["lightbox_path"][0] ) ) {
                    $lightbox_path = $custom["lightbox_path"][0];
                } else {
                    $lightbox_path = '';
                }

                $empty_thumb = '<img class="portfolios_single_thumb portfolio-image" src="' . get_template_directory_uri() . '/images/thumb.png" width="' . $post_img_width . '" height="' . $post_img_height . '" alt="' . $post->post_title . '" />';

                if ( isset( $project_img_ID ) ) {

                    if ( is_numeric( $project_img_ID ) ) {

                        $thumb_ID = $project_img_ID;
                        $thumb = wp_get_attachment_image( $thumb_ID, 'mav-thumbnails', false, array( 'class' => 'portfolios_post_image_thumb portfolio-image', 'alt' =>  $post->post_title ) );

                        if ( empty ($thumb) ) {
                            $thumb = $empty_thumb;
                        }

                    } elseif( $project_img_ID != "" ) {

                        $thumb = '<div class="project_iframe_thumb-$term_slug"><iframe width="' . $post_img_width . '" height="' . $post_img_height . '" src="' . $project_img . '" title="' . $project_img_ID . '" frameborder="0" allowfullscreen></iframe></div>';

                    } else {

                        $thumb = $empty_thumb;

                    }

                } else {
                    $thumb = $empty_thumb;
                }

            }
            ?>

            <article id="project-<?php the_ID(); ?>" class="element <?php foreach ($terms as $term) { echo strtolower(preg_replace('/\s+/', '-', $term->slug)). ' '; } ?>">

                <?php
                /**
                 * Generate the Project Image (Thumb)
                 */
                if ( $lightbox_path != '' ) { ?>
                <figure class="thumb-container">
                    <a href="<?php echo esc_attr( $lightbox_path ); ?>" data-rel="prettyPhoto" title="<?php the_title_attribute(); ?>">
                        <span class="overlay lightbox"></span>
                        <?php mav_framework_project_label( $post, array( 'portfolios-project-label' ) ); ?>
                        <?php echo( $thumb ); ?>
                    </a>
                </figure> <!-- /end .thumb-container -->
                <?php
                } elseif ($portfolio_permalink) {
                ?>
                <figure class="thumb-container">
                    <a target="_blank" href="<?php echo esc_attr( $portfolio_permalink ); ?>" rel="bookmark">
                        <span class="overlay link"></span>
                        <?php mav_framework_project_label( $post, array( 'portfolios-project-label' ) ); ?>
                        <?php echo( $thumb ); ?>
                    </a>
                </figure> <!-- /end .thumb-container -->
                <?php } else { ?>
                <figure class="thumb-container">
                    <a href="<?php the_permalink() ?>" rel="bookmark">
                        <span class="overlay">
                            <span class="view"><?php _e( 'View', 'mav_framework' ); ?></span>
                        </span>
                        <?php mav_framework_project_label( $post, array( 'portfolios-project-label' ) ); ?>
                        <?php echo( $thumb ); ?>
                    </a>
                </figure> <!-- /end .thumb-container -->
                <?php } // end Generate the Project Image (Thumb) ?>

                <h2 class="project-title">
                    <?php if ($portfolio_permalink) { ?>
                    <a target="_blank" href="<?php echo esc_url( $portfolio_permalink ); ?>" rel="bookmark"><?php the_title(); ?></a>
                    <?php } else { ?>
                    <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
                    <?php } ?>
                </h2>

                <?php if ($portfolio_desc) { ?><p class="project-description"><?php echo do_shortcode(stripslashes($portfolio_desc)); ?></p><?php } ?>


                <footer class="entry-meta">

                    <span class="posted-on">
                        <?php _e( '<span class="posted-on-title">Posted on: </span>', 'mav_framework' ); ?><a href="<?php the_permalink() ?>"><?php /* http://codex.wordpress.org/Formatting_Date_and_Time */ echo get_the_date('F j, Y'); ?></a>
                    </span> <!-- /end .posted-on -->

                    <?php
                    $project_categories = wp_get_object_terms($post->ID, 'project_category');
                    if ($project_categories) { ?>
                    <span class="cat-links">
                        <?php
                            _e( '<span class="cat-links-title">Category: </span>', 'mav_framework' );
                            $project_category = array();
                            foreach($project_categories as $category) {
                                $project_category[] = '<a href="'.get_home_url().'/?project_category=' . $category->slug . '">' . $category->name . '</a>';
                            }
                            echo implode(', ', $project_category);
                        ?>
                    </span> <!-- /end .cat-links -->
                    <?php } ?>

                    <?php // Project Tags
                    $project_tags = wp_get_object_terms($post->ID, 'project_tag');
                    if ($project_tags) {
                        $project_tag = array();
                        foreach($project_tags as $tag) {
                            $project_tag[] = '<a href="'.get_home_url().'/?project_tag=' . $tag->slug . '">' . $tag->name . '</a>';
                        } ?>
                        <span class="tag-links">
                            <?php _e( '<span class="tag-links-title">Tagged: </span>', 'mav_framework' ); ?> <?php echo implode(', ', $project_tag); ?>
                        </span> <!-- /end .tag-links -->
                    <?php } ?>

                </footer> <!-- /end .entry-meta -->

            </article> <!-- /end #project-<?php the_ID(); ?> .element -->

            <?php endwhile; ?>

            <?php wp_reset_query(); ?>

        </section> <!-- /end #projects -->

        </div> <!-- /end .wrapper -->

    </section> <!-- /end #content -->

<?php endif; ?>

<?php
/**
 * Add portfolio bottom quote
 */
if ( $mav_data['portfolio_quote_text'] ) : ?>
<section id="portfolio-quote" class="clearfix">
    <div class="wrapper clearfix">
    <?php get_template_part( 'inc/block_portfolio_quote' ); ?>
    </div> <!-- /end .wrapper -->
</section> <!-- /end #portfolio-quote -->
<?php endif; ?>

<?php get_footer(); ?>


这个问题与Wordpress本身无关,而是与您或您的主题用来排序数据的插件有关

在本例中,它使用的是过滤页面上显示的结果

通过在过滤方面解决问题,我们发现可以通过函数或按钮来完成过滤,在这种情况下,我们将两者结合使用,因为我们希望在单击时更改数据,但同时它已经需要按照您的要求进行过滤

所以,为了解决这个问题,同位素的函数文件中只有一行:

$container.isotope({
            itemSelector : '.element',
            filter: '.workshops'
        });
我刚刚加了最后一个

除此之外,您只需破解提供的代码,即可将“选定”类添加到按钮:

echo( '<ul id="filters" class="option-set">

                        <li><a href="#" data-filter="*" class="show-all">All</a></li>' );

                        foreach ( $categories as $category ) { ?>

                        <li>
                            <span class="sep">/</span>
                            <a href="#<?php echo $category->slug; ?>" <?php if($category->slug == 'workshops'): echo 'class="selected"'; endif;?>data-filter=".<?php echo $category->slug; ?>"><?php echo $category->name;?></a>
                        </li>

                        <?php 
                        }

                        echo( '</ul>' );
回声('
  • (),; foreach($categories作为$category){?>
  • /

  • 我很难理解你想要什么。你能显示工作页面的链接吗?@nunorbatista非常感谢你的回复。由于URL还没有上线,是否可以私下给它发消息?另外,这里有一个屏幕截图:这是用户第一次登陆时看到的。然而,我只希望看到“新”下的项目着陆时显示的过滤器,因此“旧”在着陆时不可见,仅在按下“旧”过滤器或“全部”时显示。但在着陆时,仅显示“新”下的项目将显示。我现在明白你想要什么了。你的代码非常大,你应该把它分成几个部分以便于阅读。我现在没有时间看,明天再看!我检查了你的代码,如果不检查网站,我将无法帮你。访问我的个人资料,访问我的网站并填写表格,我将从那里帮助你。@nu诺巴蒂斯塔太棒了!我填写了联系表。谢谢!太棒了!你帮了我很大的忙。谢谢!