نمایش لیست موضوعات به صورت دراپ دان

[short_link]

برای نمایش لیست دسته بندی های سایت میشه از کد زیر استفاده کرد. این کد دارای تنظیماتی هست که می تونید با تغییر اون به خروجی دلخواه خودتون برسید.

به طور پیش فرض نام select  ایجاد شده cat  هست که اگر بخواید توی یه فرم از چند لیست دسته بندی استفاده کنید با مشکل مواجه می شید برای همین می تونید برای هر کدوم نام جداگانه انتخاب کنید تا با هم تداخل نداشته باشن  حتی می تونید براشون کلاس های متفاوتی تعریف کنید و استایل خاص هر کدوم رو براشون بنویسید

 

<?php $args = array(
	'show_option_all'    => '',
	'show_option_none'   => '',
	'option_none_value'  => '-1',
	'orderby'            => 'ID',
	'order'              => 'ASC',
	'show_count'         => 0,
	'hide_empty'         => 1,
	'child_of'           => 0,
	'exclude'            => '',
	'include'            => '',
	'echo'               => 1,
	'selected'           => 0,
	'hierarchical'       => 0,
	'name'               => 'cat',
	'id'                 => '',
	'class'              => 'postform',
	'depth'              => 0,
	'tab_index'          => 0,
	'taxonomy'           => 'category',
	'hide_if_empty'      => false,
	'value_field'	     => 'term_id',
);

echo wp_dropdown_categories( $args );


 ?>



By default, the usage shows:

 

    • Sorts by category id in ascending order

 

    • Does not show the count of posts within a category

 

    • Does not show ’empty’ categories

 

    • Excludes nothing

 

    • Displays (echos) the categories

 

    • No category is ‘selected’ in the form

 

    • Does not display the categories in a hierarchical structure

 

    • Assigns ‘cat’ to the form name

 

    • Assigns the form to the class ‘postform’

 

    • No select ID so will default to ‘name’

 

    • Class of postform

 

    • No depth limit

 

    • Tab index of 0

 

    • Use taxonomy = category

 

    • Hide dropdown if no terms returned

 

    • Outputs the term ID upon selecting the dropdown option

 

لینک منبع 1

لینک 2


(0) دیدگاه برای این پست ثبت شده
دیدگاه خود را بفرستید
  1. اولین نفری باشید که دیدگاه خود را ثبت می کند!
« مشکل عدم ثبت درخواست برداشت در دکان
تمپلت gravitypdf »
wefwegwegweg/wp-content/themes/future