为什么我的可过滤公文包页面在Slug按钮和Slug输出WORDRPESS之间不能完美地工作?

时间:2021-03-31 作者:N. Arifin

我目前在Wordpress中有一个公文包自定义页面,可以根据需要工作,但我有一个问题。问题是,当我单击其中一个slug按钮时,主体/输出不是我想要的那样工作,例如在slug IOS中有3个项目,当我单击IOS slug中的“显示3个项目”时,应该是这样,但在这只显示1个项目。

我读过很多类似于这个问题的教程,但都没有解决,请有人帮帮我,我一直在尝试解决这个问题,但仍然没有成功。

以下是我读过的一篇文章:https://danny.care/a-responsive-filterable-portfolio-tutorial-for-wordpress/ , How to create filterable portfolio in WordPress?How to display the rest of categories on Portfolio filterable.

这就是我目前的情况:

<!-- Content
============================================= -->
<section id="content">

    <div class="content-wrap">

        <div class="container clearfix">

            <!-- Portfolio Filter
         ============================================= -->
            <ul id="portfolio-filter" class="portfolio-filter clearfix" data-container="#portfolio">

                <li class="activeFilter"><a href="#" data-filter="*">Show All</a></li>
                <?php
                $terms = get_terms("workcategory");
                $count = count($terms);
                if ( $count > 0 ){
                    foreach ( $terms as $term ){
                        ?>
                        <li><a href="#" data-filter=".pf-<?php echo $term->slug ?>">
                                <?php echo $term->name." (".$term->count.")";?>
                            </a></li>
                    <?php } } ?>

            </ul><!-- #portfolio-filter end -->

            <div id="portfolio-shuffle" class="portfolio-shuffle" data-container="#portfolio">
                <i class="icon-random"></i>
            </div>

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

            <!-- Portfolio Items
                ============================================= -->
            <div id="portfolio" class="portfolio grid-container portfolio-nomargin clearfix">

                <?php
                $args = array(\'post_type\' => \'ourworks\',
                    \'posts_per_page\'=> -1,
                    \'orderby\'       => \'DESC\');
                $query = new WP_Query($args);
                if( $query->have_posts() ) :
                    while ( $query->have_posts() ) : $query->the_post();
                        /* grab the url for the full size featured image */
                        $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),\'full\');
                        $terms_ourworks = get_the_terms( $post->ID, \'workcategory\');
                        ?>

                        <article class="portfolio-item pf-<?php echo $terms_ourworks[0]->slug; ?>">
                            <div class="portfolio-image">
                                <?php
                                add_filter( \'post_thumbnail_html\', \'remove_width_attribute\', 10 );
                                add_filter( \'image_send_to_editor\', \'remove_width_attribute\', 10 );
                                the_post_thumbnail();
                                ?>
                                <div class="portfolio-overlay">
                                    <a href="<?php echo $featured_img_url; ?>" class="left-icon" data-lightbox="image"><i class="icon-line-plus"></i></a>
                                    <a href="<?php the_permalink(); ?>" class="right-icon"><i class="icon-line-ellipsis"></i></a>
                                </div>
                            </div>
                            <div class="portfolio-desc">
                                <?php
                                the_title( sprintf( \'<h3 class="entry-title"><a href="%s" rel="bookmark">\',
                                    esc_url( get_permalink() ) ), \'</a></h3>\' );
                                ?>
                                <span>
                           <?php
                           $categories_list = get_the_term_list( $post->ID, \'workcategory\', \'\', \', \' );
                           if ( $categories_list ) {
                               /* translators: 1: list of categories. */
                               printf(esc_html__( \'%1$s\', \'afterclass\' ), $categories_list );
                           }
                           ?>
                       </span>
                            </div>
                        </article>
                    <?php endwhile; endif; wp_reset_postdata(); ?>

            </div><!-- #portfolio end -->

        </div>

    </div>

</section><!-- #content end -->
有人能查一下我的密码吗?

这是当前状态:enter image description here

源代码中的输出如下:

<article class="portfolio-item pf-<?php echo $terms_ourworks[0]->slug; ?>">

1 个回复
SO网友:N. Arifin

解决了,这部分的问题pf-, 所以,我只需要改变一下pf-<?php echo $terms_ourworks[0]->slug; 到这个<?php echo $terms_ourworks[0]->slug; ?>