提问人:Roberto 提问时间:10/6/2021 最后编辑:Roberto 更新时间:10/6/2021 访问量:316
显示更多并切片动态 div
show more and slice dynamic div
问:
我显示了动态 div,然后在单击中显示更多显示其余部分 2。就我而言,该按钮通过切片显示一次显示更多内容,我如何将其更改为显示,例如我们按切片 2 发布帖子。所有工作,只是,切片工作一次后第一次显示然后变得不起作用。我的目标是按切片显示帖子,例如我们有帖子,我们确实显示更多
$(document).ready(function() {
$('.show-less').hide();
$(".show-more").click(function() {
$('.show-block').toggleClass('show-block hide-block').toggle();
$(this).prev().find('.hide-block').slice(0, 2).toggleClass('hide-block show-block').css({
"display": "block",
visibility: 'visible'
});
$('.show-less').show();
});
$(".show-less").click(function() {
$('.show-block').toggleClass('show-block hide-block').toggle();
$('.show-more').show();
$(this).hide();
});
});
<?php
$custom_terms = get_terms('genre');
foreach ($custom_terms as $custom_term) {
wp_reset_query();
$postsPerPage = -1;
$current_category = "";
$args = [
'post_type' => 'film',
'posts_per_page' => $postsPerPage,
'orderby' => 'id',
'order' => 'ASC',
'tax_query' => [
[
'taxonomy' => 'genre',
'field' => 'slug',
'terms' => $custom_term->slug,
],
],
];
$loop = new WP_Query($args);
$parent_included = false;
if ($loop->have_posts()) {
echo '<h2 class="text-actualites">' . $custom_term->name . '</h2>';
$counter = 0;
//$count_posts = count($loop->have_posts());
$i = 0;
while ($loop->have_posts()) :
$loop->the_post();
$i++;
$img = get_field('image', "$post->ID");
$cat = $custom_term->term_id;
$current_category = $cat;
if ($custom_term->name == "Adventure") {
?>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<div class="card1 recrutements">
<div class="card-header">
<div>
<img src=<?php echo $img["url"]; ?> class='mymap-icon' alt=''>
</div>
<div>
<span class="titre-recrutement">
<div class="bnt-makers ">Communiqué de presse </div>
<div> <?php echo get_the_date(); ?></div>
<div class="bnt-maker "><?php the_field('nom', $post->ID); ?>
</div>
</div>
</div>
<div class="card-body">
<p><?php the_field('description', $post->ID); ?> </p>
<a class="dedcription-btn pop recrut" href="<?php the_permalink(); ?>" rel="nofollow">
<span class="name-descripeion">En savoir plus</span>
<div class="btn-icon">
<i class="fas fa-chevron-right"></i>
</div>
</a>
</div>
</div>
</div>
<?php
} else {
$counter++;
if (!$parent_included) {
echo '<div id="parentId">';
$parent_included = true;
}
?>
<div class="col-lg-16 col-md-6 col-sm-12 col-xs-12" class="content">
<?php
if ($counter <= 2) {
echo ("<div class='card recrutements'>");
} else {
echo ("<div class='card recrutements hide-block' id='$cat'>");
//var_dump($cat); data-id='$cat'
}
?>
<div class="card-header">
<div>
<img src=<?php echo $img["url"]; ?> class='mymap-icon' alt=''>
</div>
<div>
<span>
<div><?php echo '<p>' . $custom_term->name . '</p>'; ?>
</div>
<div> <?php echo get_the_date(); ?></div>
<div class="bnt-maker "><?php the_field('nom', $post->ID); ?>
</div>
</div>
</div>
<div class="card-body">
<p><?php the_field('description', $post->ID); ?> </p>
<a class="dedcription-btn pop recrut" href="<?php the_permalink(); ?>" rel="nofollow">
<span class="name-descripeion">En savoir plus</span>
<div class="btn-icon">
<i class="fas fa-chevron-right"></i>
</div>
</a>
</div>
</div>
</div>
<?php
}
endwhile;
echo('</div>');
}
if ($custom_term->count > 2) {
echo ("<div class='show-more' data-id='$current_category'>Show more</div>");
}
}
?>
答: 暂无答案
评论
toggle()
style
display: none
display: block
toggleClass
toggle
display
$('.show-less').show();