Admin_Apple_Meta_Boxes::build_sections_field PHP Method

build_sections_field() public static method

Builds the sections dropdown
public static build_sections_field ( array $sections, integer $post_id )
$sections array
$post_id integer
    public static function build_sections_field($sections, $post_id)
    {
        // Make sure we have sections
        if (empty($sections)) {
            return '';
        }
        // Get current sections and determine if the article was previously published
        $apple_news_sections = get_post_meta($post_id, 'apple_news_sections', true);
        // Iterate over the list of sections.
        foreach ($sections as $section) {
            ?>
			<div class="section">
				<input id="apple-news-section-<?php 
            echo esc_attr($section->id);
            ?>
" name="apple_news_sections[]" type="checkbox" value="<?php 
            echo esc_attr($section->links->self);
            ?>
" <?php 
            checked(self::section_is_checked($apple_news_sections, $section->links->self, $section->isDefault));
            ?>
>
				<label for="apple-news-section-<?php 
            echo esc_attr($section->id);
            ?>
"><?php 
            echo esc_html($section->name);
            ?>
</label>
			</div>
			<?php 
        }
    }

Usage Example

?>
		<?php 
do_action('apple_news_before_single_settings');
?>
		<table class="form-table">
			<?php 
if (!empty($sections)) {
    ?>
			<tr>
				<th scope="row"><?php 
    esc_html_e('Sections', 'apple-news');
    ?>
</th>
				<td>
					<?php 
    \Admin_Apple_Meta_Boxes::build_sections_field($sections, $post->ID);
    ?>
					<p class="description"><?php 
    esc_html_e('Select the sections in which to publish this article. Uncheck them all for a standalone article.', 'apple-news');
    ?>
</p>
				</td>
			</tr>
			<?php 
}
?>
			<tr>
				<th scope="row"><?php 
esc_html_e('Preview?', 'apple-news');
?>
</th>