• Resolved rinse

    (@rinse)


    Currently my main page needs to display a different set of posts on every day of the week. To accomplish this I made seven categories each named a different day of the week… From there I used the below to only get those posts with a category name that matched the name of the current day.

    <?php
    // get current day:
    $currentday = date('l');
    ?>
    
    <?php
     global $post;
     $today = get_posts('numberposts=6&category_name='.$currentday);
     foreach($today as $post) :
       setup_postdata($post);
     ?>
    post stuff.
    <?php endforeach; ?>

    The problem now is I’ve split my sites content into two different sections, and I want the stuff from both sections displaying on my main page. Where the problem lies is in my added category structure my ‘daily’ categories no longer have a slug of just ‘monday’ or ‘tuesday’…
    the new ones are ‘monday-stuff’, ‘tuesday-stuff’ etc. how to I go about adding the new slug to something like $currentdaynew? And from there displaying only categories $currentday & $currentdaynew? I know next to nothing about php so any help would be much appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • as multiple category names would not work with get_posts(), you would need to get the category ids first; (untested):

    `<?php
    // get current day:
    $currentday = date(‘l’);
    $currentdaynew = date(‘l’).’-stuff’;

    $cd_cat_id = get_term_by( ‘slug’, $currentday, ‘category’ );
    $cd_cat_id = $cd_cat_id->term_id;
    $cdn_cat_id = get_term_by( ‘slug’, $currentdaynew, ‘category’ );
    $cdn_cat_id = $cdn_cat_id->term_id;

    ?>

    <?php
    global $post;
    $today = get_posts(‘numberposts=6&category=’.$cd_cat_id.’,’.$cdn_cat_id);
    foreach($today as $post) :
    setup_postdata($post);
    ?>
    post stuff.
    <?php endforeach; ?>`

    Thread Starter rinse

    (@rinse)

    That appears to have solved it.
    Thank-you so much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display posts tagged with current day’ is closed to new replies.