Skip to content

Commit

Permalink
Merge pull request #1688 from greenpeace/post-category-links
Browse files Browse the repository at this point in the history
Add setting to link to category directly
  • Loading branch information
Inwerpsel authored Apr 26, 2022
2 parents 12b91f6 + e37853f commit 5c5a9ce
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/Features/PostPageCategoryLinks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace P4\MasterTheme\Features;

use P4\MasterTheme\Feature;
use P4\MasterTheme\Settings\InformationArchitecture;

/**
* @see description()
*/
class PostPageCategoryLinks extends Feature {

/**
* @inheritDoc
*/
public static function id(): string {
return 'post_page_category_links';
}


/**
* @inheritDoc
*/
protected static function name(): string {
return __( 'Post Page Category Links', 'planet4-master-theme-backend' );
}

/**
* @inheritDoc
*/
protected static function description(): string {
return __(
'On post pages, link to the categories, instead of a page that has the same category ("issue pages").',
'planet4-master-theme-backend'
);
}

/**
* @inheritDoc
*/
protected static function options_key(): string {
return InformationArchitecture::OPTIONS_KEY;
}

/**
* @inheritDoc
*/
public static function show_toggle_production(): bool {
return true;
}
}
12 changes: 12 additions & 0 deletions src/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace P4\MasterTheme;

use P4\MasterTheme\Features\PostPageCategoryLinks;
use Timber\Post as TimberPost;
use Timber\Term as TimberTerm;
use WP_Block;
Expand Down Expand Up @@ -178,6 +179,17 @@ public function set_issues_links() {
$explore_page_id = $options['explore_page'] ?? '';
$categories = get_the_category( $this->ID );

if ( PostPageCategoryLinks::is_active() ) {
$this->issues_nav_data = array_map(
fn( $category ) => [
'name' => $category->name,
'link' => get_term_link( $category ),
],
array_filter( $categories, fn( $category ) => 'uncategorised' !== $category->slug )
);
return;
}

// Handle navigation links.
if ( $categories ) {
$categories_ids = [];
Expand Down
1 change: 1 addition & 0 deletions src/Settings/Features.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use P4\MasterTheme\Features\NewDesignCountrySelector;
use P4\MasterTheme\Features\NewDesignNavigationBar;
use P4\MasterTheme\Features\PurgeOnFeatureChanges;
use P4\MasterTheme\Features\PostPageCategoryLinks;
use P4\MasterTheme\Loader;
use P4\MasterTheme\Settings;

Expand Down
2 changes: 2 additions & 0 deletions src/Settings/InformationArchitecture.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use P4\MasterTheme\Features\ActionPostType;
use P4\MasterTheme\Features\MobileTabsMenu;
use P4\MasterTheme\Features\DropdownMenu;
use P4\MasterTheme\Features\PostPageCategoryLinks;
use P4\MasterTheme\Loader;

/**
Expand Down Expand Up @@ -48,6 +49,7 @@ public static function get_fields(): array {
MobileTabsMenu::get_cmb_field(),
ActionPostType::get_cmb_field(),
DropdownMenu::get_cmb_field(),
PostPageCategoryLinks::get_cmb_field(),
];
}

Expand Down

0 comments on commit 5c5a9ce

Please sign in to comment.