3

I need wrap date and all events in one day to div "obal_date" but this not work. The number of events may be different, but I need wrap date + all events. Please how can I do that. Thank you very much.

<?php

# This will hold what group we're in
$current_header = '';

# The Loop
while ( $the_query->have_posts() ) :
    $the_query->the_post();

    $temp_date = get_post_meta( get_the_ID(), 'datum_eventu', true );

    echo '<div class="obal_over">'; 

    if ( $temp_date != $current_header ) {
        $current_header = $temp_date;
    /*****************output date******************/
    ?>

        <div class="obal_date">

        <?php
            echo "<span class='date'>".date("d", strtotime($current_header))."</span>";
            echo "<span class='month'>".date("M", strtotime($current_header))."</span>";
        ?>

        </div>     
    <?php
    /*****************date end******************/
    }
    /*****************All event action1, action2....******************/
    $title = get_post_meta( get_the_ID(), 'nazev_eventu', true );
    $cas = get_post_meta( get_the_ID(), 'cas_eventu', true );

    echo '<div class="obal_single">';   
        echo "<span class='cas'>".$cas."</span>";
        echo "<span class='title'>".$title."</span>";
    echo '</div>';  
    echo '</div>';  
    /*****************End event action1, action2....******************/
endwhile;

?>

EDIT1:

I need get:

div -> date -> action1 -> action2 -> /div

<div class="obal_over">
  <div class="obal_date">
  01Sep
  </div>
  <div class="obal_single">City1 title</div>
  <div class="obal_single">City1 title2</div>
  <div class="obal_single">City3 title</div>
</div>
//..... other date and action again start class="obal_over"

But I get

div -> date -> action -> /div -> div -> action2 -> /div

<div class="obal_over">
  <div class="obal_date">
  01Sep
  </div>
  <div class="obal_single">City1 title</div>
</div>   
<div class="obal_over"> 
  <div class="obal_single">City1 title2</div>
</div>
<div class="obal_over"> 
  <div class="obal_single">City3 title</div>
</div>

Previous question

Tomvo
  • 33
  • 1
  • 6

1 Answers1

0

To facilitate the way you want to list dates and city titles, I added a div tag outside the while loop. Then started div with obal_over class (along with end div tag) in the if condition where you check whether the dates are same or different. Also added end div tag outside while loop to provide proper open and closed div tags. I think this would work. I can't test...

    <?php

# This will hold what group we're in
$current_header = '';
echo '<div>';
# The Loop
while ( $the_query->have_posts() ) :
    $the_query->the_post();       

    $temp_date = get_post_meta( get_the_ID(), 'datum_eventu', true );        

    if ( $temp_date != $current_header ) {
        $current_header = $temp_date;
        echo '</div>';
        echo '<div class="obal_over">'; 
    /*****************output date******************/
    ?>
        <div class="obal_date">

        <?php
            echo "<span class='date'>".date("d", strtotime($current_header))."</span>";
            echo "<span class='month'>".date("M", strtotime($current_header))."</span>";
        ?>

        </div>     
    <?php
    /*****************date end******************/
    }
    /*****************All event action1, action2....******************/
    $title = get_post_meta( get_the_ID(), 'nazev_eventu', true );
    $cas = get_post_meta( get_the_ID(), 'cas_eventu', true );

    echo '<div class="obal_single">';   
        echo "<span class='cas'>".$cas."</span>";
        echo "<span class='title'>".$title."</span>";
    echo '</div>';  

    /*****************End event action1, action2....******************/



endwhile;
echo '</div>';
?>
T.Shah
  • 2,768
  • 1
  • 14
  • 13
  • Hello thank you for your answer, I am getting in result only 01Jan. When I change in `for` current_header to current_headers it is works good, but now I am getting only one div `
    ` for all event and date :(
    – Tomvo Nov 01 '17 at 11:55
  • I get `
    all data
    not separate -> obal_date ->obal_single -> again ... .Please can you solve this ? :) Thank you !
    – Tomvo Nov 01 '17 at 12:07
  • I made little changes to your code .. please check. – T.Shah Nov 01 '17 at 13:57
  • That's it ! Thank you very much you ! :) Have a great day. Now I'm happy :D. I have something similar but my mistake was `echo ''; echo '
    '; ` . Thank you one more :)
    – Tomvo Nov 01 '17 at 14:16