Beitragsnavigation – Link von Post zu Post

Wie man mit Hilfe von kleinen CodeSchnipseln innerhalb eines Beitrags zum nächsten oder vorherigen Post gelangen kann, soll hier mit entsprechenden Beispielen aufgezeigt werden.

Variante #1 – posts_nav_link()

Diese Funktion scheint schon etwas älter zu sein und wird von der aktuellen WP-Version (3.8 & größer) nicht mehr unterstützt.
Zumindest konnte ich mit diesem Code keine Ausgabe erzeugen.
Dennoch möchte ich diese Funktion kurz anreißen.

// Anwendung
posts_nav_link( $sep, $prelabel, $nxtlabel )
// INFO
$sep // optional. Separator for posts navigation links.
$prelabel // optional. Label for previous pages.
$nxtlabel // optional. Label for next pages.

Ein weiterer Blick in die Datei wp-includes/link-template.php zeigt, dass es die Funktion seit WordPress 0.71 gibt – quasi ein Urgestein der WordPress-Geschichte.

Variante #2 – previous_post() & next_post()

Die Funktionen previous_post() (seit Version 1.5) und next_post() (seit Version 0.71) funktionieren, wurden aber mit Veröffentlichung der Version 2.0 als deprecated deklariert.

// Anwendung & Info
previous_post(
$format, // [string] Default = '%'
$previous, // [string] Default = 'previous post: '
$title, // [string] Default = 'yes'
$in_same_cat, // [string] Default = 'no'
$limitprev, // [int] Default = 1
$excluded_categories // [string] Default = ''
)
// Anwendung & Info
next_post(
$format, // [string] Default = '%'
$next, // [string] Default = 'next post: '
$title, // [string] Default = 'yes'
$in_same_cat, // [string] Default = 'no'
$limitnext, // [int] Default = 1
$excluded_categories // [string] Default = ''
)

Variante #3 – previous_post_link() & next_post_link()

Hierbei handelt es sich um die aktuellsten Funktionen zur Generierung der Links zum nächsten bzw. vorherigen Post.

Funktion previous_post_link()

Link zum vorherigen Post.

// Anwendung
previous_post_link( $format, $link, $in_same_cat, $excluded_terms, $taxonomy )
// INFO
$format // Default = '« %link'
optional. Link anchor format.
$link // Default = '%title'
optional. Link permalink format.
$in_same_cat // Default = false
optional. Whether link should be in a same taxonomy term.
$excluded_terms // Default = ''
optional. Array or comma-separated list of excluded term IDs.
$taxonomy // Default = 'category'
optional. Taxonomy, if $in_same_term is true.

Funktion next_post_link()

Link zum nächsten Post.

// Anwendung
next_post_link( $format, $link, $in_same_cat, $excluded_terms, $taxonomy )
// INFO
$format // Default = '%link »'
optional. Link anchor format.
$link // Default = '%title'
optional. Link permalink format.
$in_same_cat // Default = false
optional. Whether link should be in a same taxonomy term.
$excluded_terms // Default = ''
optional. Array or comma-separated list of excluded term IDs.
$taxonomy // Default = 'category'
optional. Taxonomy, if $in_same_term is true.

Schreibe einen Kommentar

* Pflichtfelder