Skip to content

Instantly share code, notes, and snippets.

@barbietunnie
Forked from danielpataki/admin-style.php
Last active September 13, 2015 17:32
Show Gist options
  • Save barbietunnie/ef28f524e4179c19ca61 to your computer and use it in GitHub Desktop.
Save barbietunnie/ef28f524e4179c19ca61 to your computer and use it in GitHub Desktop.
Travel Diary
function td_admin_assets() {
wp_enqueue_style( 'td-admin-post-list', get_stylesheet_directory_uri() . '/admin-style.css', false, '1.0.0' );
}
add_action( 'admin_enqueue_scripts', 'td_admin_assets' );
/*
Theme Name: Travel Diary
Theme URI: http://danielpataki.com
Description: My travel diary theme, a child of Yuuta
Author: Daniel Pataki
Author URI: http://danielpataki.com
Template: yuuta
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: traveldiary
*/
add_action( 'wp_enqueue_scripts', 'td_theme_styles' );
function td_theme_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
function td_custom_filtering( $query ) {
if ( $query->is_home() && $query->is_main_query() && !empty( $_GET['meta_key'] ) && !empty( $_GET['meta_value'] ) ) {
$query->set( 'meta_key', $_GET['meta_key'] );
$query->set( 'meta_value', $_GET['meta_value'] );
}
}
add_action( 'pre_get_posts', 'td_custom_filtering' );
<table>
<tr>
<th>Length</th>
<th>Duration</th>
<th>Difficulty</th>
<th>Trail Map</th>
</tr>
<tr>
<th><?php the_field( 'length' ) ?></th>
<th><?php the_field( 'duration' ) ?></th>
<th><?php the_field( 'difficulty' ) ?></th>
<th><a href='<?php the_field( 'trail_map' ) ?>'>View Map</a></th>
</tr>
</table>
wp_enqueue_script(
'google-maps',
'//maps.googleapis.com/maps/api/js?key=your_api_key&callback=initMap',
array(),
'1.0',
true
);
<?php $location = get_field( 'location' ); ?>
<h6>Location: <small><?php echo round( $location['lat'], 4 ) ?>, <?php echo round( $location['lng'], 4 ) ?></small></h6>
<div class='map' style='height:300px; margin-bottom: 1.6842em' id='map-<?php echo $id ?>'></div>
<script type='text/javascript'>
var map;
var map_center = {lat: <?php echo $location['lat'] ?>, lng: <?php echo $location['lng'] ?> };
function initMap() {
map = new google.maps.Map(document.getElementById('map-<?php echo $id ?>'), {
center: map_center,
zoom: 15
});
var marker = new google.maps.Marker({
position: map_center,
map: map
});
}
</script>
add_filter('manage_post_posts_columns', 'td_post_columns');
function td_post_columns( $defaults ) {
$columns = array();
$columns['cb'] = $defaults['cb'];
unset( $defaults['tags'], $defaults['author'], $defaults['cb'] );
$columns['days'] = "Days";
$columns = array_merge( $columns, $defaults );
return $columns;
}
add_filter( 'manage_edit-post_sortable_columns', 'td_post_column_ordering' );
function td_post_column_ordering( $columns ) {
$columns['days'] = 'days';
return $columns;
}
add_filter( 'request', 'td_post_column_ordering_request' );
function td_post_column_ordering_request( $vars ) {
if ( isset( $vars['orderby'] ) && 'days' == $vars['orderby'] ) {
$vars = array_merge( $vars, array(
'meta_key' => 'days',
'orderby' => 'meta_value_num',
) );
}
return $vars;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment