Skip to content
Permalink
Browse files

Add handling for "Draft" category posts

- 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 049575f9a40f3e6b2f21db809765826fce231b10
Showing with 37 additions and 0 deletions.
  1. +37 −0 salferrarello-com-mods.php
@@ -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.

@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.
You can’t perform that action at this time.