Created
May 31, 2020 06:48
-
-
Save Postnov/5c0a4ca2286e50297ecc8c42e045af52 to your computer and use it in GitHub Desktop.
Предыдущий и следующий пост. Полная кастомизация. Проработано отсутствие одного из постов.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? if (current_user_can( 'administrator' )): ?> | |
<? | |
$previousPost = get_previous_post(); | |
$nextPost = get_next_post(); | |
$currentPost = get_post(); | |
$projectsPosts = get_posts( | |
array( | |
'post_type' => 'projects', | |
'posts_per_page' => -1, | |
'orderby'=> 'ASC', | |
'exclude' => $currentPost->ID, $previousPost->ID, $next_post->ID | |
) | |
); | |
$additionalPost; | |
foreach( $projectsPosts as $post ){ | |
$postHide = get_field('hide_in_projects', $postID); | |
if ($postHide == 0) { | |
$additionalPost = $post; | |
} | |
} | |
if(empty($next_post)) { | |
$next_post = $additionalPost; | |
} | |
if(empty($previousPost)){ | |
$previousPost = $additionalPost; | |
} | |
?> | |
<div class="switch-project"> | |
<a class="switch-project-button" href="<?=$previousPost->guid;?>"> | |
<span class="switch-project-subtitle">Предыдущий проект</span> | |
<p class="switch-project-title"><?=$previousPost->post_title;?></p> | |
</a> | |
<a class="switch-project-button" href="<?=$next_post->guid;?>"> | |
<span class="switch-project-subtitle">Следующий проект</span> | |
<p class="switch-project-title"><?=$next_post->post_title;?></p> | |
</a> | |
</div> | |
<? endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment