B
B
Boris Belov2016-02-24 18:58:19
PHP
Boris Belov, 2016-02-24 18:58:19

How to hide a block if there are more than 3 entries?

Hello.
There is a block.
In which two arrays are displayed, one displays the entries attached to the "Curators" entry, and the latest entries "Upcoming events"
v29LxQkhGNyDYm.jpg
There is not much space for the block, and I came up with the idea to do such a thing.
So that if there are more than 3 curators, then the "Upcoming events" block will have to disappear.
How to make this?
-----
My code on curated block output

<div class="kuratori">
<?php
$posts = get_field('lektori');
if ($posts) { ?>  
<h2>Кураторы</h2>  
    <?php foreach($posts as $post) { setup_postdata($post); ?>

<div class="meropriyatiya">
<?php 
$params = array('post_status' => 'future','post__not_in' => array($post->ID),);$the_query = new WP_Query($params); ?>
 <?php while  ($the_query->have_posts() ) : $the_query->the_post(); ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Khokhlov, 2016-02-24
@andrhohlov

You need to wrap the block of events in a condition. If I'm not mistaken it should be like this:

if (count($posts) < 3) {
 // блок мероприятий
}

php.net/manual/en/function.count.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question