|
67 | 67 | if ( ! is_utf8_charset() ) { |
68 | 68 | add_settings_field( 'blog_charset', __( 'Encoding for pages and feeds' ), 'options_reading_blog_charset', 'reading', 'default', array( 'label_for' => 'blog_charset' ) ); |
69 | 69 | } |
70 | | -?> |
71 | | - |
72 | | -<?php if ( ! get_pages() ) : ?> |
73 | | -<input name="show_on_front" type="hidden" value="posts" /> |
74 | | -<table class="form-table" role="presentation"> |
75 | | - <?php |
76 | | - if ( 'posts' != get_option( 'show_on_front' ) ) : |
77 | | - update_option( 'show_on_front', 'posts' ); |
78 | | - endif; |
79 | | - |
80 | 70 | /** |
81 | 71 | * this fillter overrides which post type are show in the dropdown |
82 | 72 | * |
|
88 | 78 | */ |
89 | 79 | $post_types_allowed_on_home_page = apply_filters( 'post_types_allowed_on_home_page', array_keys( get_post_types( array( 'show_in_home_page_list' => true ) ) ) ); |
90 | 80 | $args = array( |
91 | | - 'post_type' => $post_types_allowed_on_home_page, |
92 | | - 'post_status' => 'publish', |
93 | | - 'fields' => 'ids' |
| 81 | + 'post_type' => $post_types_allowed_on_home_page, |
| 82 | + 'post_status' => 'publish', |
| 83 | + 'fields' => 'ids' |
94 | 84 | ); |
95 | 85 | $allowed_pages = new WP_Query( $args ); |
| 86 | +?> |
| 87 | + |
| 88 | +<?php if ( ! get_pages() ) : ?> |
| 89 | +<input name="show_on_front" type="hidden" value="posts" /> |
| 90 | +<table class="form-table" role="presentation"> |
| 91 | + <?php |
| 92 | + if ( 'posts' != get_option( 'show_on_front' ) ) : |
| 93 | + update_option( 'show_on_front', 'posts' ); |
| 94 | + endif; |
| 95 | +endif; |
| 96 | + |
96 | 97 |
|
97 | | -//if ( empty( $allowed_pages->posts ) ) : ?> |
98 | | -<!--<input name="show_on_front" type="hidden" value="posts" />--> |
99 | | -<!--<table class="form-table" role="presentation">--> |
100 | | -<!-- <tr>--> |
101 | | -<!-- <th scope="row">--><?php //_e( 'Your homepage displays' ); ?><!--</th>--> |
102 | | -<!-- <td>--><?php |
103 | | -// $content_type_links = array(); |
104 | | -// foreach ($post_types_allowed_on_home_page as $type ){ |
105 | | -// $content_type_links[] = sprintf('<a href="%s">%s</a>', |
106 | | -// 'edit.php?post_type=' . $type, ucfirst( $type ) ); |
107 | | -// } |
108 | | -// printf( |
109 | | -// /* translators: %s: URL to Pages screen. */ |
110 | | -// __( 'No selectable pages found! Add at least one of these content types %s' ), |
111 | | -// implode( ', ', $content_type_links ) |
112 | | -// ); |
113 | | -// ?> |
114 | | -<!-- </td>--> |
115 | | -<!-- --><?php |
116 | | -// if ( 'posts' !== get_option( 'show_on_front' ) ) : |
117 | | -// update_option( 'show_on_front', 'posts' ); |
118 | | -// endif; |
119 | | -// |
120 | | -//else : |
121 | 98 | if ( 'page' === get_option( 'show_on_front' ) && ! get_option( 'page_on_front' ) && ! get_option( 'page_for_posts' ) ) { |
122 | 99 | update_option( 'show_on_front', 'posts' ); |
123 | 100 | } |
|
130 | 107 | <td id="front-static-pages"><fieldset> |
131 | 108 | <legend class="screen-reader-text"><span><?php echo $your_homepage_displays_title; ?></span></legend> |
132 | 109 | <p><label> |
133 | | - <input name="show_on_front" type="radio" value="posts" class="tog" <?php |
| 110 | +<?php |
134 | 111 | $allowed_archives_on_home_page = array( 'posts') + $post_types_allowed_on_home_page; |
135 | 112 | unset( $allowed_archives_on_home_page['page'] ); |
136 | | - checked( in_array( get_option( 'show_on_front' ), $allowed_archives_on_home_page, true ) ); ?> /> |
137 | | - <?php |
138 | 113 | if( 1 === count( $allowed_archives_on_home_page ) ) { |
139 | | - _e( 'Your latest posts' ); |
| 114 | + _e( sprintf( 'Your latest %s', get_post_type_object( $allowed_archives_on_home_page[0] )->labels->name ) ); |
| 115 | + ?><input name="show_on_front" type="hidden" value="<?php echo esc_attr( $allowed_archives_on_home_page[0] ); ?>" /> <?php |
140 | 116 | } else { |
141 | | - $output = "<select name='show_archive_on_front' id='homepage_types'>\n"; |
| 117 | + $output = "<select name='show_on_front' id='homepage_types'>\n"; |
| 118 | + $output .= sprintf( '<option value="page" %s>A static page (select below)</option>', selected( -1, strtolower( get_option( 'show_on_front' ) ), false ) ) ; |
142 | 119 | foreach ( $allowed_archives_on_home_page as $post_type ){ |
143 | 120 | $post_type = ( 'posts' === $post_type ) ? 'post' : $post_type; |
144 | | - $output .= sprintf( '<option %s>%s</option>', $post_type, get_post_type_object( $post_type )->labels->name ) ; |
| 121 | + $output .= sprintf( '<option value="%s" %s>%s</option>', |
| 122 | + $post_type, |
| 123 | + selected( $post_type, strtolower( get_option( 'show_on_front' ) ),false ), |
| 124 | + sprintf( __( 'Your latest %s' ), get_post_type_object( $post_type )->labels->name ) |
| 125 | + ) ; |
145 | 126 | } |
146 | 127 | $output .= "</select>\n"; |
147 | 128 |
|
148 | | - printf( __( 'Your latest %s' ), $output ); |
| 129 | + echo $output; |
149 | 130 | } |
150 | 131 | ?> |
151 | 132 | </label> |
|
166 | 147 | </p> |
167 | 148 | <?php else : ?> |
168 | 149 | <p><label> |
169 | | - <input name="show_on_front" type="radio" value="page" class="tog" <?php checked( 'page', get_option( 'show_on_front' ) ); ?> /> |
| 150 | +<!-- <input name="show_on_front" type="radio" value="page" class="tog" --><?php //checked( 'page', get_option( 'show_on_front' ) ); ?><!-- />--> |
170 | 151 | <?php |
171 | | - printf( |
172 | | - /* translators: %s: URL to Pages screen. */ |
173 | | - __( 'A <a href="%s">static page</a> (select below)' ), |
174 | | - 'edit.php?post_type=page' |
175 | | - ); |
| 152 | +// printf( |
| 153 | +// /* translators: %s: URL to Pages screen. */ |
| 154 | +// __( 'A <a href="%s">static page</a> (select below)' ), |
| 155 | +// 'edit.php?post_type=page' |
| 156 | +// ); |
176 | 157 | ?> |
177 | 158 | </label> |
178 | 159 | </p> |
|
190 | 171 | ); |
191 | 172 | $cpt_posts = new WP_Query( $args ); |
192 | 173 | foreach ( $cpt_posts->posts as $cpt_post ) { |
193 | | - $output .= sprintf( '<option %s>%s</option>', $cpt_post->ID, $cpt_post->post_name ) ; |
| 174 | + $output .= sprintf( '<option value="%s" %s>%s</option>', |
| 175 | + $cpt_post->ID, |
| 176 | + selected( $cpt_post->ID, get_option( 'page_on_front' ),false ), |
| 177 | + $cpt_post->post_name ) ; |
194 | 178 | } |
195 | 179 | $output .= '</optgroup>'; |
196 | 180 | } |
|
0 commit comments