lundi 3 décembre 2018

Conditional css for unordered list dependent on time entered

my php programming knowledge is pretty basic and does have holes in it but if some one could help me resolve the below issue I'd be eternally grateful.

I've created a list of items that each have a 1) Title, 2) Link, 3) Date & 4) description, and are inputed via the ACF (Advanced Custmom Fields) plugin on a wordpress site. I have included the code to display this list on the front end of the website below - please note there are a series of lists meaning there are nested lists (called sub repeater) inside the main one (called parent repeater).

However... I wish to style differently any entries (inputted into the sub repeater list) which are newer that 30 days.

So . . . I presume I need to create a conditional "if" statement that changes the name of the css class for any <li> in the sub repeater list ('item_list_details') which was added/entered less than 30 days ago. Please can someone explain how I can generate this condition within the code below:

<?php 
// check for rows (parent repeater)
if( have_rows('membership_lists_links') ): ?>
    <?php 
    // loop through rows (parent repeater)
    while( have_rows('membership_lists_links') ): the_row(); ?>
       <div>
            <h2 class="acf-admin"><?php the_sub_field('item_list_title'); ?></h2>
            <?php 
            // check for rows (sub repeater)
            if( have_rows('item_list_details') ): ?>
                <ul class="admin">
                <?php
                // loop through rows (sub repeater)
                while( have_rows('item_list_details') ): the_row() 
                    // display each item as a list
                    ?>
                       <li><div class='itemTitle'>
                                <?php $link = get_sub_field('link_url'); if( $link ): ?>
                                <a href="<?php echo $link['url']; ?>" target="<?php echo $link['target']; ?>" title="<?php echo $link['title']; ?>">
                                <?php endif; ?>
                                <?php the_sub_field('link_name'); ?>
                                <?php $link = get_sub_field('link_url'); if( $link ): ?>
                                </a>
                                <?php endif; ?>
                            </div>
                            <div class="memberListDate">
                                <?php the_sub_field('date'); ?>
                            </div>
                            <br/>
                            <div class="itemDescription">
                                <?php the_sub_field('link_description'); ?>
                            </div>
                        </li>   
                <?php endwhile; ?>
                </ul>
            <?php endif; //if( get_sub_field('section_details') ): ?>
        </div>
    <?php endwhile; // while( has_sub_field('business_sections') ): ?>

I presume that the section of the code that starts off . . .

<?php // check for rows (sub repeater)
if( have_rows('item_list_details') ): ?>

is where the date age condition needs to be defined and then each <li> within that loop would have a differnt css class name dependent on whether it was entered earlier than 30 days ago? Then, as the entry became older than 30 days its css class would change to the other css name.

I hope I've explained myself well enough and would very much appreciate any help with achieving this.

Many thanks

Phil

Aucun commentaire:

Enregistrer un commentaire