Ankerlink an den Anfang der Seite
john ogroats 1008672 1920
Generic filters
Filter by Kategorien

Der Beitrag, geschriebem am 18. Juli 2018, ist schon etwas älter und könnte womöglich nicht mehr aktuell sein

Die Standardpagination von WooCommerce in Produktübersichten hat neben Seitenzahlenlinks auch Links zur vorherigen und nächsten Seite. Für ein Projekt das sehr viele Produkte bekommen sollte, wurde gewünscht, dass es auch noch Links zur ersten und zur letzten Seite gibt, wie in nachfolgender Abbildung.

pagination woocommerce plus

Wer WooCommerce kennt weiß, dass es viele Templates hat, unter anderem eines für die Pagination. Das kann einfach überschrieben werden, indem die Datei pagination.php aus dem WooCommerce-Ordner templates/loop/ in den (Child-)Theme-Ordner woocommerce/loop/ kopiert und dort modifiziert wird.

<?php
/**
 * Pagination - Show numbered pagination for catalog pages
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/loop/pagination.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see     https://docs.woocommerce.com/document/template-structure/
 * @package WooCommerce/Templates
 * @version 3.3.1
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$total   = isset( $total ) ? $total : wc_get_loop_prop( 'total_pages' );
$current = isset( $current ) ? $current : wc_get_loop_prop( 'current_page' );
$base    = isset( $base ) ? $base : esc_url_raw( str_replace( 999999999, '%#%', remove_query_arg( 'add-to-cart', get_pagenum_link( 999999999, false ) ) ) );
$format  = isset( $format ) ? $format : '';

if ( $total <= 1 ) {
	return;
}
?>
<nav class="woocommerce-pagination">
	<?php
		/* nachfolgende Variablen ersetzen mit gewünschen Klassen / Icons */
		$first = __('First', 'my_text_domain');
		$last = __('Last', 'my_text_domain');
		$previous = __('previos', 'my_text_domain');
		$next = __('next', 'my_text_domain');

		$lifirst = $current > 1 ? '<li class="page-num page-num-first"><a href='.esc_url(get_pagenum_link(1)).'>'.esc_html($first).' </a></li>' : '';
		$lilast = $current < $total ? '<li class="page-num page-num-first"><a href='.esc_url(get_pagenum_link($total)).'>'.esc_html($last).' </a></li>' : '';

		$pages = paginate_links( apply_filters( 'my_woo_pagination_args', array( 
			'base'         => $base,
			'format'       => $format,
			'add_args'     => false,
			'current'      => max( 1, $current ),
			'total'        => $total,
			'prev_text'    => $previous,
			'next_text'    => $next,
			'type'         => 'array',
			'end_size'     => 3,
			'mid_size'     => 3
		) ) );		

		if ( is_array( $pages ) ) {
			echo '<ul class="page-numbers">';
			echo $lifirst;
			foreach ( $pages as $page ) {
					echo "<li>$page</li>";
			}
			echo $lilast;
		   	echo '</ul>';
		}
	?>
</nav>

Bitte das Kommentarfeld nicht für Supportanfragen nutzen; hier kann kein Support angeboten werden. Die Angabe von Name oder E-Mail-Adresse ist optional, ein Spitzname wäre trotzdem nett.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Hinweis: Name und E-Mail-Adresse (beides optional, da alle Kommentare moderiert werden) werden dauerhaft gespeichert. Über dieses Formular kann jeder Zeit die Löschung persönlicher Daten oder Kommentare angefordert werden; die Anfrage wird nicht veröffentlicht und nach der Bearbeitung gelöscht. IP-Adressen, die mit Kommentaren gespeichert werden, werden nach zwei Monaten automatisch gelöscht.

Ihre Nachricht wird möglicherweise zur Spam-Prüfung an OpenAI (USA) weitergeleitet. Weitere Informationen finden Sie in unserer Datenschutzerklärung.