calculation
-
Mike
Firstly I would like to thank you for all the time you spend answering questions and supporting people like me! I do still need a bit more help though please. I had put this on the end of my last question but as it was marked as recolved think you probably didn’t see it.I have set up the query to select those posts where the meta key birthday value is current day and call the-wp-tiles to display a grid of those with a birthday today. (code in my customised content.php is here).
<?php $query = new WP_Query( array( 'meta_key' => 'birthday', 'meta_value' => date( 'F d' ) )); $opts = array( 'byline_template' => "%title%", 'byline_template_textonly' => false, 'byline_opacity' => '0.6', 'byline_color' => '#000000', 'byline_height' => 30, 'byline_height_auto' => false, 'text_color' => false, 'image_text_color' => '#FFFF99', ' image_size' => 'original', 'post_type'=>'post', 'orderby'=>'title', 'order'=>'ASC', 'posts_per_page'=>'auto', ' pagination' => none, 'category'=>'join', 'extra_classes'=> array(my-custom-styled-tiles), 'post_status'=>'publish'); ?> <?php the_content(); ?> </div><!-- .entry-content --> <?php the_wp_tiles( $query, $opts); ?> <?php wp_reset_postdata(); ?>
On this particular page where I use the-wp-tiles query I am only selecting those whose birthday it is and would like to say on these bylines how old they are (or even just in a caption to go under the tile??). I don’t want it on any other page that the same tiles appear in various groupings but will just print the age variable on the text on some posts.
I store the birthdate as a post tag in the format ‘d-m-Y’ (eg 22-03-1996). I have tried to create a function in functions.php to calculate the age in years for example but seem to have problems getting it to read the tag ‘birthdate’ from the post as a variable:function get_age( $birthdate )
{
list($day, $month, $year) = explode( “-“, $birthdate);// Find the differences
$y_diff = date( “Y” ) – $year;
$m_diff = date( “m” ) – $month;
$d_diff = date( “d” ) – $day;// check if another year has been reached
if ( $d_diff < 0 || $m_diff < 0 )
$y_diff –;
return $y_diff;So firstly this function code to calculate the age isn’t working (something wrong with my code) it won’t seem to pick up my tag field variable $birthdate.
Secondly when I manage to get this bit of coding correct I need to pass this info to the-wp-tiles query so that for each post it returns (whose birthday it is today) it also returns the age and puts it onto the byline or as a tile caption.Would appreciate any help you can offer.
- The topic ‘calculation’ is closed to new replies.