Skip to content

Instantly share code, notes, and snippets.

@designbuildtest
Created March 5, 2015 09:14
Show Gist options
  • Select an option

  • Save designbuildtest/28ca93348d446104986f to your computer and use it in GitHub Desktop.

Select an option

Save designbuildtest/28ca93348d446104986f to your computer and use it in GitHub Desktop.
Announcement Customizer & HTML
if ( current_theme_supports( 'announcement' ) ) {
function announcement_customizer( $wp_customize ) {
$wp_customize->add_section( 'announcement', array(
'title' => __( 'Announcement' ),
'description' => __( 'A summary of this page will appear in the header area of your website.' ),
'priority' => 64,
)
);
$wp_customize->add_setting( 'announcement_page', array(
'type' => 'option',
'sanitize_callback' => 'absint',
)
);
$wp_customize->add_control( 'announcement_page', array(
//'label' => __( 'Select a page' ),
'type' => 'dropdown-pages',
'section' => 'announcement',
)
);
}
add_action( 'customize_register', 'announcement_customizer' );
function announcement_html() {
$page_id = get_option( 'announcement_page' );
if ( $page_id ) {
$args = array(
'page_id' => $page_id,
);
$primary = new WP_Query( $args );
if ( $primary->have_posts() ) : ?>
<div class="announcement">
<div class="container">
<?php while ( $primary->have_posts() ) : $primary->the_post(); ?>
<article><?php the_excerpt(); ?></article>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</div>
</div><?php
endif;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment