1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
<div class="cover--nav">
<?php
$currenttPostId = get_the_ID();
$theCategory = get_the_terms(get_the_ID(),'custom_category');
global $wp_query;
$args = array(
'post_type' => 'articlecustom',
'orderby' => 'rand',
'post_status' => 'publish',
'recipe_category'=> !empty($theCategory) ? $theCategory[0]->slug : '',
'post__not_in' => array($currenttPostId),
'posts_per_page' => 2,
);
$post_query = new WP_Query($args);
$prevNext = array();
if ( $post_query->have_posts() ) :
while ( $post_query->have_posts() ) : $post_query->the_post();
array_push( $prevNext, get_the_ID() );
endwhile;
endif;
wp_reset_postdata();
if (!empty($prevNext)) {
$prevPostID = $prevNext[0];
if($prevPostID) {
?>
<a class="cover--nav-prev" href="<?php echo get_permalink($prevPostID); ?>">
<span class="cover--nav-label"><?php _e('Recette précédente', 'marque'); ?></span>
<svg class="icon icon-arrow-prev" role="presentation" focusable="false"><use xlink:href="<?php echo get_template_directory_uri(); ?>/images/symbol-defs.svg#icon-arrow-prev"></use></svg>
</a>
<?php } ?>
<?php
$nextPostID = $prevNext[1];
if( $nextPostID ) {
?>
<a class="cover--nav-next" href="<?php echo get_permalink($nextPostID); ?>">
<span class="cover--nav-label"><?php _e('Article suivant', 'marque'); ?></span>
<svg class="icon icon-arrow-next" role="presentation" focusable="false"><use xlink:href="<?php echo get_template_directory_uri(); ?>/images/symbol-defs.svg#icon-arrow-next"></use></svg>
</a>
<?php }
} ?>
</div> |
Partager