WordPress开发者和主题制作者的搜索引擎



build_dropdown_script_block_core_categories ›

Sincen/a
已弃用n/a
build_dropdown_script_block_core_categories ( $dropdown_id )
参数:
  • (string) $dropdown_id ID of the dropdown field.
    Required: Yes
返回:
  • (string) Returns the dropdown onChange redirection script.
定义在:
文档:

Generates the inline script for a categories dropdown field.



源码

function build_dropdown_script_block_core_categories( $dropdown_id ) {
	ob_start();
	?>
	<script type='text/javascript'>
	/* <![CDATA[ */
	( function() {
		var dropdown = document.getElementById( '<?php echo esc_js( $dropdown_id ); ?>' );
		function onCatChange() {
			if ( dropdown.options[ dropdown.selectedIndex ].value > 0 ) {
				location.href = "<?php echo home_url(); ?>/?cat=" + dropdown.options[ dropdown.selectedIndex ].value;
			}
		}
		dropdown.onchange = onCatChange;
	})();
	/* ]]> */
	</script>
	<?php
	return ob_get_clean();
}