atravelblog/functions.php

118 lines
3.8 KiB
PHP
Raw Normal View History

2016-09-07 20:11:06 +02:00
<?php
add_action( 'wp_enqueue_scripts', 'td_theme_styles' );
function td_theme_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
2016-09-07 21:09:58 +02:00
wp_enqueue_script(
'google-maps',
'//maps.googleapis.com/maps/api/js?key=AIzaSyDHNT102YHu-TP50F78bPyvf5ia6K6cjU8&callback=initMap',
array(),
'1.0',
true
);
2016-09-07 20:11:06 +02:00
}
// Add google API key
function my_acf_google_map_api( $api ){
$api['key'] = 'AIzaSyDHNT102YHu-TP50F78bPyvf5ia6K6cjU8';
return $api;
}
add_filter('acf/fields/google_map/api', 'my_acf_google_map_api');
2016-09-11 16:28:51 +02:00
// Only show posts of category Urlaub (id=2)
function my_home_category( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'cat', '2');
}
}
add_action( 'pre_get_posts', 'my_home_category' );
2016-09-11 16:59:35 +02:00
2016-09-11 16:28:51 +02:00
// Related posts function
function atravelblog_related_posts() {
global $post;
$thisID = get_the_ID();
$cat = get_the_category()[0]->name;
if ( $cat == 'Urlaub' ){
2016-09-12 12:59:53 +02:00
$tagebuch = new WP_Query( array(
'category_name' => 'Tagebuch',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'urlaub', // name of custom field
2016-09-12 13:34:55 +02:00
'value' => get_the_ID(), // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => '='
)
)
2016-09-12 12:59:53 +02:00
) );
if ($tagebuch->have_posts()) :
2016-09-12 13:30:01 +02:00
echo('<h4 style="color: white; margin-top: 20px;" class="section-inner">Tagebuch Einträge:</h4>');
2016-09-12 12:55:49 +02:00
echo('<div class="related-posts posts section-inner">');
while ( $tagebuch->have_posts() ) : $tagebuch->the_post();
global $post;
get_template_part( 'content', get_post_format() );
endwhile;
2016-09-12 12:55:49 +02:00
echo('<div class="clear"></div>');
echo('</div> <!-- /related-posts -->');
endif;
2016-09-12 12:55:49 +02:00
wp_reset_query();
2016-09-12 13:36:50 +02:00
$album = new WP_Query( array(
'category_name' => 'Album',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'urlaub', // name of custom field
'value' => get_the_ID(), // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => '='
)
)
) );
if ($album->have_posts()) :
echo('<h4 style="color: white; margin-top: 20px;" class="section-inner">Fotoalben:</h4>');
echo('<div class="related-posts posts section-inner">');
while ( $album->have_posts() ) : $album->the_post();
global $post;
get_template_part( 'content', get_post_format() );
endwhile;
echo('<div class="clear"></div>');
echo('</div> <!-- /related-posts -->');
endif;
wp_reset_query();
$touren = new WP_Query( array(
'category_name' => 'Tour',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'urlaub', // name of custom field
'value' => get_the_ID(), // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => '='
)
)
) );
if ($touren->have_posts()) :
echo('<h4 style="color: white; margin-top: 20px;" class="section-inner">Touren:</h4>');
echo('<div class="related-posts posts section-inner">');
while ( $touren->have_posts() ) : $touren->the_post();
global $post;
get_template_part( 'content', get_post_format() );
endwhile;
echo('<div class="clear"></div>');
echo('</div> <!-- /related-posts -->');
endif;
wp_reset_query();
} elseif($cat == 'Tour' || $cat == 'Album' || $cat == 'Tagebuch') {
2016-09-12 12:51:51 +02:00
$urlaub = new WP_Query(array('p' => get_field('urlaub')[0]));
2016-09-12 12:35:03 +02:00
if ($urlaub->have_posts()) :
2016-09-12 13:30:01 +02:00
echo('<h4 style="color: white; margin-top: 20px;" class="section-inner">Urlaub:</h4>');
2016-09-12 12:55:49 +02:00
echo('<div class="related-posts posts section-inner">');
2016-09-12 12:35:03 +02:00
while ( $urlaub->have_posts() ) : $urlaub->the_post();
global $post;
2016-09-12 12:52:08 +02:00
get_template_part( 'content', get_post_format() );
2016-09-12 12:35:03 +02:00
endwhile;
2016-09-12 12:55:49 +02:00
echo('<div class="clear"></div>');
echo('</div> <!-- /related-posts -->');
2016-09-12 12:35:03 +02:00
endif;
2016-09-12 12:55:49 +02:00
wp_reset_query();
}
2016-09-11 16:59:35 +02:00
}