Skip to content

Commit

Permalink
Add handling for "Draft" category posts
Browse files Browse the repository at this point in the history
- Add warning alert to "Draft" category posts.
- Exclude "Draft" category posts from homepage.

See #1
  • Loading branch information
salcode committed Apr 26, 2018
1 parent 60815df commit 049575f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions salferrarello-com-mods.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,40 @@ function sf_genesis_pre_load_favicon( $favicon_url ) {
$plugin_dir_path = plugin_dir_url(__FILE__);
return $plugin_dir_path . 'images/favicon.ico';
}

/**

This comment has been minimized.

Copy link
@GaryJones

GaryJones May 8, 2018

DocBlocks should go immediately above the function it's documenting, not above the global add_*() call.

* Add a warning alert on Draft posts.
*/
add_action( 'genesis_entry_header', 'sf_genesis_draft_notice' );
function sf_genesis_draft_notice() {
global $post;
if ( ! in_category( 'draft', $post ) ) {
// Make no changes.
return;
}
?>
<br />
<div class="alert alert-warning" role="alert">
<strong>Warning!</strong>
This is a draft, not a finalized post. See <a href="https://salferrarello.com/draft-blog-posts/">full draft disclosure</a>.
</div>
<?php
}

/**
* Exclude Draft posts from the blog page (which is also my homepage).
*/
add_filter( 'pre_get_posts', 'sf_exclude_draft_category' );
function sf_exclude_draft_category( $query ) {
if ( $query->is_home ) {
$query->set( 'tax_query', [
[
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'draft',
'operator' => 'NOT IN',
],
] );
}
return $query;
}

0 comments on commit 049575f

Please sign in to comment.