PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.2
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.2
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / presentations / archive-adjacent-trait.php

archive-adjacent-trait.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.2, at src/presentations/archive-adjacent-trait.php

73 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Presentations;
4
5 use Yoast\WP\SEO\Helpers\Pagination_Helper;
6 use Yoast\WP\SEO\Models\Indexable;
7
8 /**
9 * Class Archive_Adjacent.
10 *
11 * Presentation object for indexables.
12 *
13 * @property Indexable $model The indexable.
14 * @property Pagination_Helper $pagination The pagination helper. Should be defined in the parent
15 * class because of trait issues in PHP 5.6.
16 */
17 trait Archive_Adjacent {
18
19 /**
20 * Sets the helpers for the trait.
21 *
22 * @required
23 *
24 * @codeCoverageIgnore
25 *
26 * @param Pagination_Helper $pagination The pagination helper.
27 */
28 public function set_archive_adjacent_helpers( Pagination_Helper $pagination ) {
29 $this->pagination = $pagination;
30 }
31
32 /**
33 * Generates the rel prev.
34 *
35 * @return string
36 */
37 public function generate_rel_prev() {
38 if ( $this->pagination->is_rel_adjacent_disabled() ) {
39 return '';
40 }
41
42 $current_page = \max( 1, $this->pagination->get_current_archive_page_number() );
43 // Check if there is a previous page.
44 if ( $current_page === 1 ) {
45 return '';
46 }
47 // Check if the previous page is the first page.
48 if ( $current_page === 2 ) {
49 return $this->get_permalink();
50 }
51
52 return $this->pagination->get_paginated_url( $this->get_permalink(), ( $current_page - 1 ) );
53 }
54
55 /**
56 * Generates the rel next.
57 *
58 * @return string
59 */
60 public function generate_rel_next() {
61 if ( $this->pagination->is_rel_adjacent_disabled() ) {
62 return '';
63 }
64
65 $current_page = \max( 1, $this->pagination->get_current_archive_page_number() );
66 if ( $this->pagination->get_number_of_archive_pages() <= $current_page ) {
67 return '';
68 }
69
70 return $this->pagination->get_paginated_url( $this->get_permalink(), ( $current_page + 1 ) );
71 }
72 }
73