Skip to content

Commit

Permalink
Merge pull request #767 from Automattic/adds/category
Browse files Browse the repository at this point in the history
Add classes for the category and tags to the primary `<section>`
  • Loading branch information
laurelfulford authored Feb 11, 2020
2 parents fb521f0 + dc4f5d8 commit 263cd02
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
14 changes: 14 additions & 0 deletions newspack-theme/inc/template-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,20 @@ function newspack_post_classes( $classes, $class, $post_id ) {
}
add_filter( 'post_class', 'newspack_post_classes', 10, 3 );

/**
* Gets the category and tag classes from the post.
*/
function newspack_get_category_tag_classes( $post_id ) {
$post_classes = get_post_class( '', $post_id );
$cat_tag_classes = array();
foreach ( $post_classes as $post_class ) {
if ( 0 === strpos( $post_class, 'category-' ) || 0 === strpos( $post_class, 'tag-' ) ) {
$cat_tag_classes[] = $post_class;
}
}
return implode( ' ', $cat_tag_classes );
}

/**
* Add a pingback url auto-discovery header for single posts, pages, or attachments.
*/
Expand Down
2 changes: 1 addition & 1 deletion newspack-theme/single-feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
get_header();
?>

<section id="primary" class="content-area">
<section id="primary" class="content-area <?php echo esc_attr( newspack_get_category_tag_classes( get_the_ID() ) ); ?>">
<main id="main" class="site-main">

<?php
Expand Down
2 changes: 1 addition & 1 deletion newspack-theme/single-wide.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
get_header();
?>

<section id="primary" class="content-area">
<section id="primary" class="content-area <?php echo esc_attr( newspack_get_category_tag_classes( get_the_ID() ) ); ?>">
<main id="main" class="site-main">

<?php
Expand Down
2 changes: 1 addition & 1 deletion newspack-theme/single.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
get_header();
?>

<section id="primary" class="content-area">
<section id="primary" class="content-area <?php echo esc_attr( newspack_get_category_tag_classes( get_the_ID() ) ); ?>">
<main id="main" class="site-main">

<?php
Expand Down

0 comments on commit 263cd02

Please sign in to comment.