Refactoring
This commit is contained in:
parent
3e21e36eeb
commit
c2b4cbeccb
1 changed files with 31 additions and 76 deletions
107
functions.php
107
functions.php
|
|
@ -38,93 +38,48 @@ function my_home_category( $query ) {
|
||||||
|
|
||||||
add_action( 'pre_get_posts', 'my_home_category' );
|
add_action( 'pre_get_posts', 'my_home_category' );
|
||||||
|
|
||||||
|
function add_post_image_thumbs($WPQuery, $title){
|
||||||
|
if ($WPQuery->have_posts()) :
|
||||||
|
echo('<h4 style="color: white; margin-top: 20px;" class="section-inner">'.$title.'</h4>');
|
||||||
|
echo('<div class="related-posts posts section-inner">');
|
||||||
|
while ( $WPQuery->have_posts() ) : $WPQuery->the_post();
|
||||||
|
global $post;
|
||||||
|
get_template_part( 'content', get_post_format() );
|
||||||
|
endwhile;
|
||||||
|
echo('<div class="clear"></div>');
|
||||||
|
echo('</div> <!-- /related-posts -->');
|
||||||
|
endif;
|
||||||
|
}
|
||||||
|
|
||||||
// Related posts function
|
// Related posts function
|
||||||
function atravelblog_related_posts() {
|
function atravelblog_related_posts() {
|
||||||
global $post;
|
global $post;
|
||||||
$thisID = get_the_ID();
|
$thisID = get_the_ID();
|
||||||
|
$thisUrlaubConf = array(
|
||||||
|
'posts_per_page' => -1,
|
||||||
|
'order' => 'ASC',
|
||||||
|
'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' => 'LIKE'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
$cat = get_the_category()[0]->name;
|
$cat = get_the_category()[0]->name;
|
||||||
if ( $cat == 'Urlaub' ){
|
if ( $cat == 'Urlaub' ){
|
||||||
$tagebuch = new WP_Query( array(
|
$tagebuch = new WP_Query( array_merge($thisUrlaubConf, array('category_name' => 'Tagebuch')) );
|
||||||
'category_name' => 'Tagebuch',
|
add_post_image_thumbs($tagebuch, 'Tagebuch Einträge:');
|
||||||
'posts_per_page' => -1,
|
|
||||||
'order' => 'ASC',
|
|
||||||
'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' => 'LIKE'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
) );
|
|
||||||
if ($tagebuch->have_posts()) :
|
|
||||||
echo('<h4 style="color: white; margin-top: 20px;" class="section-inner">Tagebuch Einträge:</h4>');
|
|
||||||
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;
|
|
||||||
echo('<div class="clear"></div>');
|
|
||||||
echo('</div> <!-- /related-posts -->');
|
|
||||||
endif;
|
|
||||||
wp_reset_query();
|
wp_reset_query();
|
||||||
$album = new WP_Query( array(
|
$album = new WP_Query( array_merge($thisUrlaubConf, array('category_name' => 'Album')) );
|
||||||
'category_name' => 'Album',
|
add_post_image_thumbs($album, 'Fotoalben:');
|
||||||
'posts_per_page' => -1,
|
|
||||||
'order' => 'ASC',
|
|
||||||
'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' => 'LIKE'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
) );
|
|
||||||
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();
|
wp_reset_query();
|
||||||
$touren = new WP_Query( array(
|
$tour = new WP_Query( array_merge($thisUrlaubConf, array('category_name' => 'Tour')) );
|
||||||
'category_name' => 'Tour',
|
add_post_image_thumbs($tour, 'Touren:');
|
||||||
'posts_per_page' => -1,
|
|
||||||
'order' => 'ASC',
|
|
||||||
'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' => 'LIKE'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
) );
|
|
||||||
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();
|
wp_reset_query();
|
||||||
} elseif($cat == 'Tour' || $cat == 'Album' || $cat == 'Tagebuch') {
|
} elseif($cat == 'Tour' || $cat == 'Album' || $cat == 'Tagebuch') {
|
||||||
$urlaub = new WP_Query(array('p' => get_field('urlaub')[0]));
|
$urlaub = new WP_Query(array('p' => get_field('urlaub')[0]));
|
||||||
if ($urlaub->have_posts()) :
|
add_post_image_thumbs($urlaub, 'Urlaub:');
|
||||||
echo('<h4 style="color: white; margin-top: 20px;" class="section-inner">Urlaub:</h4>');
|
|
||||||
echo('<div class="related-posts posts section-inner">');
|
|
||||||
while ( $urlaub->have_posts() ) : $urlaub->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();
|
wp_reset_query();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue