PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
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 trunk, at src/presentations/archive-adjacent-trait.php

80 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 */
15 trait Archive_Adjacent {
16
17 /**
18 * Holds the Pagination_Helper instance.
19 *
20 * @var Pagination_Helper
21 */
22 protected $pagination;
23
24 /**
25 * Sets the helpers for the trait.
26 *
27 * @required
28 *
29 * @codeCoverageIgnore
30 *
31 * @param Pagination_Helper $pagination The pagination helper.
32 *
33 * @return void
34 */
35 public function set_archive_adjacent_helpers( Pagination_Helper $pagination ) {
36 $this->pagination = $pagination;
37 }
38
39 /**
40 * Generates the rel prev.
41 *
42 * @return string
43 */
44 public function generate_rel_prev() {
45 if ( $this->pagination->is_rel_adjacent_disabled() ) {
46 return '';
47 }
48
49 $current_page = \max( 1, $this->pagination->get_current_archive_page_number() );
50 // Check if there is a previous page.
51 if ( $current_page === 1 ) {
52 return '';
53 }
54 // Check if the previous page is the first page.
55 if ( $current_page === 2 ) {
56 return $this->permalink;
57 }
58
59 return $this->pagination->get_paginated_url( $this->permalink, ( $current_page - 1 ) );
60 }
61
62 /**
63 * Generates the rel next.
64 *
65 * @return string
66 */
67 public function generate_rel_next() {
68 if ( $this->pagination->is_rel_adjacent_disabled() ) {
69 return '';
70 }
71
72 $current_page = \max( 1, $this->pagination->get_current_archive_page_number() );
73 if ( $this->pagination->get_number_of_archive_pages() <= $current_page ) {
74 return '';
75 }
76
77 return $this->pagination->get_paginated_url( $this->permalink, ( $current_page + 1 ) );
78 }
79 }
80