• robahas

    (@robahas)


    Hi – I am working on a site that makes a new post each day. The customer would like a calendar in which, when you click on the day, it opens the post for that day. Unfortunately the WP calendar widget goes to the archive page first and then you have to click on the post.

    Any ideas on how this might be accomplished? (One idea might be to use a calendar plugin and treat each post as an event, however, we have hundreds of existing post, so this is not ideal as it would involve retrofitting).

    Thanks in advance

Viewing 1 replies (of 1 total)
  • Thread Starter robahas

    (@robahas)

    Here is how I addressed this problem. Of course, this will exclude single day archives from ever showing up. In my case that is OK. You have to put this before everything else in the archives page, or call it there via a function.

    <?php
    //redirect single day archive url to the first post for that day
    $archiveURL = $_SERVER['REQUEST_URI'];
    $datePieces = explode('/', $archiveURL );
    $datePieces = array_filter($datePieces, 'strlen');
    unset($datePieces[1]); //I'm deleting this bc the site is in a sub-directory
    $datePieces = array_values($datePieces);
    	if ( count($datePieces) > 2 ) : //This leaves monthly archives (yyyy/mm/)alone
    	$my_query = new WP_Query( array(
    							'posts_per_page' => 1,
    								'date_query' => array (
    										array(
    											'year' => $datePieces[0],
    											'month' => $datePieces[1],
    											'day' => $datePieces[2], ))));
    		while( $my_query->have_posts() ) : $my_query->the_post();
    			$postURL = get_permalink();
    		endwhile;
    		header( 'location: '.$postURL );
    	endif;
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Make Calendar Widget Link to a Post, not an archive page’ is closed to new replies.