Dear bcworkz,
thank you for this very detailed answer! Your hint with the post publish date was great. Indeed this seems to be a custom post type with the publishing date as birthday. This is my final source code of the sportspress/templates/birthdays.php page – for solving my problem I just added a sort function which sorts by each player’s birthday date reduced to the actual day of month:
<?php
/**
* Birthdays
*
* @author ThemeBoy
* @package SportsPress_Birthdays
* @version 1.9.19
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
$html5 = current_theme_supports( 'html5', 'gallery' );
$defaults = array(
'date' => 'day',
'itemtag' => 'dl',
'icontag' => 'dt',
'captiontag' => 'dd',
'size' => 'sportspress-fit-medium',
'show_player_birthday' => get_option( 'sportspress_player_show_birthday', 'no' ) == 'yes' ? true : false,
'show_staff_birthday' => get_option( 'sportspress_staff_show_birthday', 'no' ) == 'yes' ? true : false,
'link_players' => get_option( 'sportspress_link_players', 'yes' ) == 'yes' ? true : false,
'link_staff' => get_option( 'sportspress_link_staff', 'yes' ) == 'yes' ? true : false,
);
extract( $defaults, EXTR_SKIP );
$args = array(
'post_type' => array( 'sp_player', 'sp_staff' ),
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'ASC',
'monthnum' => date('n'),
);
if ( $date == 'day' ) {
$args['day'] = date('j');
}
$posts = get_posts( $args );
<strong> // The new sort part
// THE SORT FUNCTION
function sort_by_day_of_month($a, $b) {
$a_postdate = get_the_date( "d" , $a->ID);
$b_postdate = get_the_date( "d" , $b->ID);
return $a_postdate - $b_postdate;
}
usort($posts, 'sort_by_day_of_month');</strong>
// FILTERS YEARS
$minimal_year = (date("Y") - 100);
foreach ( $posts as $post ) {
<strong> // The year filter part
$year_of_birth = get_the_date( "Y" , $post->ID );
if ( $year_of_birth <= $minimal_year )
{
continue;
}</strong>
echo '<div class="sp-template sp-template-birthdays sp-template-birthday-gallery sp-template-gallery">';
if ( 'sp_staff' == $post->post_type ) {
$link_posts = $link_staff;
$show_birthday = $show_staff_birthday;
} else {
$link_posts = $link_players;
$show_birthday = $show_player_birthday;
}
$birthday = get_the_date( "j. F" , $post->ID );
if ( $show_birthday && $birthday && $group !== $birthday ) {
echo '<h4 class="sp-table-caption">' . $birthday . '</h4>';
}
echo '<div class="gallery">';
$caption = $post->post_title;
$caption = trim( $caption );
sp_get_template( 'player-gallery-thumbnail.php', array(
'id' => $post->ID,
'itemtag' => $itemtag,
'icontag' => $icontag,
'captiontag' => $captiontag,
'caption' => $caption,
'size' => $size,
'link_posts' => $link_posts,
) );
echo '<br style="clear: both;" />';
echo "</div></div>\n";
}
The other capitalized commented if sequence skips players with a year of birth smaller or equals 100 years ago. This seems to be mean to people who are more than 100 years old but they don’t have any of them in their teams. Unfortunately it seems that the smallest year of a post’s date is 115 years ago. I misuse these old ages to hide players with unknown birthday because there isn’t another possibility for that.
Maybe my code is useful to another one.
Thank you again and best regards
Nico
-
This reply was modified 7 years ago by thenicnic.
-
This reply was modified 7 years ago by thenicnic.