Skip to content

Instantly share code, notes, and snippets.

@danielpataki
Last active August 29, 2015 14:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielpataki/df3c87c0529b2cf26c23 to your computer and use it in GitHub Desktop.
Save danielpataki/df3c87c0529b2cf26c23 to your computer and use it in GitHub Desktop.
Workout Diary
add_filter( 'the_content', 'show_diary_details' );
function show_diary_details( $content ) {
$diary = '';
if( has_category( 'workout' ) ) {
$diary = '<table>
<tr>
<th>Activity</th>
<th>Duration</th>
<th>Distance</th>
<th>Calories</th>
<th>Link</th>
</tr>
<tr>
<td>' . get_field( 'type' ) . '</td>
<td>' . get_field( 'duration' ) . ' min</td>
<td>' . get_field( 'distance' ) . ' km</td>
<td>' . get_field( 'calories' ) . ' kcal</td>
<td><a href="' . get_field( 'link' ) . '">link</a></td>
</tr>
</table>';
}
if( has_category( 'meal' ) ) {
$diary = '<table>
<tr>
<th>Calories</th>
<th>Fat</th>
<th>Protein</th>
<th>Carbohydrates</th>
<th>Cholesterol</th>
</tr>
<tr>
<td>' . get_field( 'calories' ) . ' kcal</td>
<td>' . get_field( 'fat' ) . ' g</td>
<td>' . get_field( 'protein' ) . ' g</td>
<td>' . get_field( 'carbohydrates' ) . ' g</td>
<td>' . get_field( 'cholesterol' ) . ' mg</td>
</tr>
</table>';
}
if( has_category( 'sleep' ) ) {
$diary = '<table>
<tr>
<th>Calories</th>
<th>Fat</th>
<th>Protein</th>
<th>Carbohydrates</th>
<th>Cholesterol</th>
</tr>
<tr>
<td>' . get_field( 'start' ) . '</td>
<td>' . get_field( 'end' ) . '</td>
</tr>
</table>';
}
return $content . $diary;
}
<?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( 'parent-style' ) );
}
/*
Theme Name: Workout Diary
Theme URI: http://yourwebsite.com/
Description: My personal workout diary
Author: Daniel Pataki
Author URI: http://danielpataki.com
Template: twentyfifteen
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
add_filter( 'the_content', 'show_diary_details' );
function show_diary_details( $content ) {
$diary = '';
if( has_category( 'workout' ) ) {
$diary = '<table>
<tr>
<th>Activity</th>
<th>Duration</th>
<th>Distance</th>
<th>Calories</th>
<th>Link</th>
</tr>
<tr>
<td>' . get_field( 'type' ) . '</td>
<td>' . get_field( 'duration' ) . ' min</td>
<td>' . get_field( 'distance' ) . ' km</td>
<td>' . get_field( 'calories' ) . ' kcal</td>
<td><a href="' . get_field( 'link' ) . '">link</a></td>
</tr>
</table>';
}
return $content . $diary;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment