jannik
10/12/2017 - 8:03 AM

Pagination with automatic singlular/plural post type names

Pagination with automatic singlular/plural post type names

<?php
$queried_object = get_queried_object();
$post_type_singular_name = $queried_object->post_type;
$obj = get_post_type_object($post_type_singular_name);
$post_type_plural_name = $obj->labels->name;
?>

<div class="row pagination pad-small">
    <div class="small-2 large-4 columns">
        <?php
        $prev_post = get_previous_post();
        if (!empty( $prev_post )): ?>
          <a href="<?php echo get_permalink( $prev_post->ID ); ?>" class="link link-xlarge arrow-left"><span>Vorige <?php echo $post_type_singular_name; ?></span></a>
        <?php else: ?>
            <a class="link link-xlarge arrow-left disabled"><span>Vorige <?php echo $post_type_singular_name; ?></span></a>
        <?php endif; ?>
    </div>
    <div class="small-8 large-4 columns">
        <a href="<?php echo home_url('referenties'); ?>" class="link link-xlarge"><span>Terug naar</span> alle <?php echo $post_type_plural_name; ?></a>
    </div>
    <div class="small-2 large-4 columns">
        <?php
        $next_post = get_next_post();
        if (!empty( $next_post )): ?>
          <a href="<?php echo get_permalink( $next_post->ID ); ?>" class="link link-xlarge arrow-right"><span>Volgende <?php echo $post_type_singular_name; ?></span></a>
        <?php else: ?>
            <a class="link link-xlarge arrow-right disabled"><span>Volgende <?php echo $post_type_singular_name; ?></span></a>
        <?php endif; ?>
    </div>
</div>