Skip to content

Instantly share code, notes, and snippets.

@mariokerkhof
Created January 30, 2016 12:57
Show Gist options
  • Save mariokerkhof/deca58936ac7bccb315a to your computer and use it in GitHub Desktop.
Save mariokerkhof/deca58936ac7bccb315a to your computer and use it in GitHub Desktop.
MKR Helper Functions
<?php
//
// Template helper functions
//
function mkr_is_first_post( $query = false ) {
if ( ! $query ) {
global $wp_query;
$query = $wp_query;
}
return $query->current_post === 0;
}
function mkr_is_second_post( $query = false ) {
if ( ! $query ) {
global $wp_query;
$query = $wp_query;
}
return $query->current_post === 1;
}
function mkr_is_third_post( $query = false ) {
if ( ! $query ) {
global $wp_query;
$query = $wp_query;
}
return $query->current_post === 2;
}
function mkr_is_last_post( $query = false ) {
if ( ! $query ) {
global $wp_query;
$query = $wp_query;
}
return ( $query->current_post + 1 ) == $query->post_count;
}
function get_date_field( $format, $key, $id = false ) {
$date = get_field( $key, $id );
return date_i18n( $format, strtotime( $date ) );
}
function the_date_field( $format, $key, $id = false ) {
echo get_date_field( $format, $key, $id );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment