同位素 - 显示每个类别中的最新帖子

Ole*_*len 15 php ajax wordpress jquery

它现在如何工作:

  • 它显示最新的6个项目为默认值
  • 按下特定列表时,它会显示该类别中最新的6个项目的最新帖子.例如:它显示了Foto中最新的4个,因为6个中的4个是Foto类别.这意味着如果6个最新项目属于Foto类别,则其他类别中的任何帖子都不会显示.如果您不明白,请参阅下面的屏幕节目.

不显示每个类别中的所有帖子

它应该如何工作:

  • 默认显示最新的6个项目(这有效)
  • 按一个类别时,它应显示该类别中的最新6个帖子

见这里的页面

注意:如果您在Windows 10中使用Chrome,则悬停效果因某些原因停止工作.该错误已报告给Chrome和Windows

<ul id="filters" class="whitetext whitelink myeluft">
    <li class="smoothtrans"><a href="#" data-filter="*" class="selected smoothtrans">Alle</a></li>
    <li class="smoothtrans"><a href='#' data-filter='.foto' class="smoothtrans">Foto</a></li>
    <li class="smoothtrans"><a href='#' data-filter='.video' class="smoothtrans">Video</a></li>
    <li class="smoothtrans"><a href='#' data-filter='.web' class="smoothtrans">Web</a></li>
</ul>
Run Code Online (Sandbox Code Playgroud)

PHP

<?php

$args = array(
    'post_type' => (array( 'foto', 'video', 'web' )),
    'posts_per_page' => '6',
    'post_taxonomy' => 'any',
);

$the_query = new WP_Query($args); 


// Loop post_type
?>

<?php if ( $the_query->have_posts() ) : ?>
    <div id="isotope-list">
        <?php while ( $the_query->have_posts() ) : $the_query->the_post(); 

        $termsArray = get_the_terms( $post->ID, "category");  //Get the terms for this particular item
        $termsString = ""; //initialize the string that will contain the terms
            foreach ( $termsArray as $term ) { // for each term 
                $termsString .= $term->slug.' '; //create a string that has all the slugs 
            }
        ?> 
        <div class="<?php echo $termsString; ?> item col-md-4"> 
            <ul class="grid cs-style-3">
                <li>
                    <figure>
                        <?php if ( has_post_thumbnail() ) { 
                              the_post_thumbnail('frontpage_thumb');
                        } ?>
                        <figcaption class="lefttext">
                            <h3><?php the_title(); ?></h3>
                            <span class="offgrey"><?php echo(types_render_field( "produkt", array( 'raw' => true) )); ?> / <?php echo(types_render_field( "produsert", array( 'raw' => true) )); ?></span>
                            <a href="<?php the_permalink() ?>" title="Se prosjekt" rel="bookmark" class="smoothtrans">Se prosjekt</a>
                        </figcaption>
                    </figure>
                </li>
            </ul>             
        </div> <!-- end item -->
        <?php endwhile;  ?>
    </div> <!-- end isotope-list -->
    <script src="<?php bloginfo('stylesheet_directory'); ?>/js/toucheffects.js"></script>
<?php endif; ?>
Run Code Online (Sandbox Code Playgroud)

JS

jQuery(function ($) {

    var $container = $('#isotope-list'); //The ID for the list with all the blog posts
    $container.isotope({ //Isotope options, 'item' matches the class in the PHP
        itemSelector : '.item', 
        layoutMode : 'masonry'
    });

    //Add the class selected to the item that is clicked, and remove from the others
    var $optionSets = $('#filters'),
    $optionLinks = $optionSets.find('a');

    $optionLinks.click(function(){
    var $this = $(this);
    // don't proceed if already selected
    if ( $this.hasClass('selected') ) {
      return false;
    }
    var $optionSet = $this.parents('#filters');
    $optionSets.find('.selected').removeClass('selected');
    $this.addClass('selected');

    //When an item is clicked, sort the items.
     var selector = $(this).attr('data-filter');
    $container.isotope({ filter: selector });

    return false;
    });

});
Run Code Online (Sandbox Code Playgroud)

我的虽然(2015年7月13日更新)

我已经更多地了解它,并且当禁用'posts_per_page'并且仅使用自定义wp设置时,问题是相同的.所以我想问题是,当按下每个类别时,它不会刷新或获得除首次显示之外的任何其他帖子.

因此我认为args必须设置在另一个地方,或者必须修改js以获得最新的帖子.但这不是我的专业知识,因此我问你是否有任何解决方案.我在搜索引擎和搜索引擎上搜索了这个问题,但我找不到它.但是,我看到类似的页面有同样的问题.有了这个,我相信解决这个问题也会有助于其他用户.

The*_*tor 5

您当前的代码仅向数据库询问最近的6个帖子.同位素插件然后在前端过滤它们.

这意味着它不能显示除此之外的更多帖子6.当您点击标签(照片,视频,网络)同位素过滤此6个帖子时,仅显示具有所选类别的帖子.它不会要求更多帖子,它只会过滤您已有的帖子.

当您单击过滤器标签时,可以让您的代码要求更多帖子,但您需要使用AJAX.


小智 0

有两件事我不明白

  1. 为什么有两个导航/选择两个导航

2.第一个工作正常,但第二个没有任何链接或功能,它仅使用#超级引用链接回相同的链接或功能。

3.视频和网络有相同的东西,如果不检查指定的类别,您是否故意放置它