build_dropdown_script_block_core_categories

函式
build_dropdown_script_block_core_categories ( $dropdown_id )
引數
  • (string) $dropdown_id ID of the dropdown field.
    Required:
返回值
  • (string) Returns the dropdown onChange redirection script.
定義位置
相關方法
render_block_core_categoriesregister_block_core_categoriesdropdown_link_categorieswp_dropdown_categoriesdropdown_categories
引入
-
棄用
-

build_dropdown_script_block_core_categories: 這個函式用來建立下拉選單,以便在類別塊中選擇一個類別。

為類別下拉欄位生成內聯指令碼。

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 esc_url( home_url() ); ?>/?cat=" + dropdown.options[ dropdown.selectedIndex ].value;
			}
		}
		dropdown.onchange = onCatChange;
	})();
	/* ]]> */
	</script>
	<?php
	return ob_get_clean();
}

常見問題

FAQs
檢視更多 >