Skip to content

Instantly share code, notes, and snippets.

@Postnov
Created May 31, 2020 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Postnov/5c0a4ca2286e50297ecc8c42e045af52 to your computer and use it in GitHub Desktop.
Save Postnov/5c0a4ca2286e50297ecc8c42e045af52 to your computer and use it in GitHub Desktop.
Предыдущий и следующий пост. Полная кастомизация. Проработано отсутствие одного из постов.
<? 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