gpt4 book ai didi

html - 同位素过滤自定义样式问题

转载 作者:行者123 更新时间:2023-11-28 00:44:51 25 4
gpt4 key购买 nike

我需要像下图一样设计同位素过滤器的样式。

enter image description here

同位素过滤 jQuery 可以做到这一点吗?

注意:- 我已经在我的 WordPress 网站中实现了这种同位素过滤。所有过滤器都是自定义帖子类型类别,右侧内容(过滤器 1 内容 A,过滤器 1 内容 B 等)是帖子类型标题,左侧内容是自定义帖子类型内容。

最佳答案

请按照以下步骤操作:

1.创建一个名为template-isotope-grid.php 的模板,并将这段代码放入其中。

<?php
/**
* The template for displaying all posts in isotope.
*
* Template Name: Isotope Grid View
*
* @package storefront
*/

get_header(); ?>
<?php
$query = new WP_Query(array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1
));
$categories = get_categories();
//print_r($categories);
?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php if ($query->have_posts()): ?>
<div id="filter-menu" class="filter-button-group">
<button data-filter="*" class="reset active row-btn">All</button>
<?php foreach($categories as $category):?>
<button data-filter=".<?php echo $category->slug;?>" class="row-btn"><?php echo $category->name; ?></button>
<?php endforeach; ?>
</div>
<div class="row">
<div class="col-md-8 col-xs-8 col-sm-8" id="content_section">
</div>


<div class="col-md-4 col-xs-4 col-sm-4">
<div id="grid">
<?php while ( $query->have_posts() ) : $query->the_post();
$categories = get_the_category(get_the_ID());
$cat_str = '';
foreach ($categories as $category) {
$cat_str .=$cat_str.' '.$category->slug;
}

echo '<div class="content-item '.$cat_str.'" style="display:none;">';
echo '<h2>'.get_the_title().'</h2>';
if (has_post_thumbnail( get_the_ID() ) ):
$image = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'single-post-thumbnail' );
echo '<div class="img_class"><img src="'.$image[0].'" /></div>';
endif;
echo '<div class="post_content">'.get_the_content().'</div>';
echo '</div>';

echo '<div class="item '.$cat_str.'">'.get_the_title().'</div>';

endwhile; // End of the loop. ?>
</div>
</div>
</div>
<?php wp_reset_query();
else:
// No, we don't have any posts, so maybe we display a nice message
echo "<p class='no-posts'>" . __( "Sorry, there are no posts at this time." ) . "</p>";
endif;
?>

</main><!-- #main -->
</div><!-- #primary -->

<?php
get_footer();
  1. 从管理员创建一个页面,然后从右侧 Isotope Grid View 选择您创建的模板。请参见屏幕截图。 enter image description here

  2. 将此 css 放入 style.css 文件中:

button {
cursor: pointer;
border: none;
background: none;
}
#filter-menu {
padding: 20px 0;
text-align: center;
}
button:focus {
outline: 0;
}

button.active {
background: grey;
}

#grid {
width: 100%;
}

#grid .item {
position: unset !important;
left: unset !important;
top: unset !important;
}
.item.selected {
font-weight: bold;
}

  1. 包含 thic boostrap 文件 header.php 文件:

    https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css

  2. 在 footer.php 文件中包含这些 js 文件:

    https://cdnjs.cloudflare.com/ajax/libs/jquery.isotope/2.2.2/isotope.pkgd.min.js https://cdn.jsdelivr.net/isotope.packery/1.3.2/packery-mode.pkgd.min.js

并将脚本放在 footer.php 文件中:

<script type="text/javascript">

var $grid = jQuery('#grid').isotope({
itemSelector: '.item',
layoutMode: 'packery',
});

jQuery(function() {
var $buttons = jQuery('#filter-menu button');
$buttons.on('click', function() {
var filterValue = jQuery(this).attr('data-filter');
jQuery(this).addClass('active').siblings().removeClass('active');
$grid.isotope({
filter: filterValue
});
});
});

jQuery(window).on('load',function(){
jQuery('#grid').find('.item').first().addClass('selected');
var firstElement = jQuery('#grid').find('.item.selected').prev().html();
console.log('Load: ',firstElement);
jQuery('#content_section').html(firstElement);
});
jQuery('button.row-btn').on('click',function(){
setTimeout(function(){
jQuery('#grid').find('.item').removeClass('selected');
jQuery('#grid').find('.item:visible').first().addClass('selected');
var firstElement = jQuery('#grid').find('.item.selected').prev().html();
console.log('Load: ',firstElement);
jQuery('#content_section').html(firstElement);
},1000);
});
jQuery(document).on('click','div.item',function(){
console.log('Load: ',firstElement);
jQuery('#grid').find('.item').removeClass('selected');
jQuery(this).addClass('selected');
var firstElement = jQuery(this).prev().html();

jQuery('#content_section').html(firstElement);

});
</script>

截图:

enter image description here enter image description here enter image description here

关于html - 同位素过滤自定义样式问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51240101/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com