Kodları lütfen aşağıdaki butonları kullanarak renklendirin. Örnek: <php> echo "Selam Dünya"; </php>
Yardım
karakter kaldı

Wordpress yenilenen selectbox

Merhaba,

Başlık soruyla ilgili fazla detaya sahip olmayabilir. Hemen açıklayayım. Yan yana iki tane "multiple" özelliğine sahip slect box'm var. Bunların ilkinde Wordpress'teki kategoriler çıkıyor. Diğerinde ise, ilk select box'mdaki seçtiğim kategorilerdeki yazıların bir listesi çıkıyor, optgroup'lanmış halde: Şunun gibi:
http://img843.imageshack.us/img843/377/6b18fffe183b41139907ca8.png

Ancak! Resimde de fark edildiği üzere çekilen yazılar çok orantısız. İkişer üçer kere çıkıyorlar. Bunu düzeltmek istiyorum işte. :)

		$temp_categories = get_categories('hide_empty=0&orderby=name');
		$categories = array();
		foreach ($temp_categories as $category)
			$categories[$category->term_id] = $category->cat_name . ' (' . $category->category_count . ')';


	echo '						<select id="post_category" name="category" multiple="multiple">';

	foreach ($categories as $catid => $catname)
		echo '
							<option id="cat_', $catid, '" value="', $catid, '">', $catname, '</option>';

	echo '
						</select>
						<span style="font-size: 3em; text-align: center; display: inline-block; margin-bottom: 8%;">»</span>
						<select id="category_posts" name="posts[]" multiple="multiple"></select>';


		$(document).ready(function() {
			$(\'#post_category\').change(get_category_posts);
		});

		function get_category_posts()
		{
			$(\'#category_posts\').empty();

			$("#post_category option:selected").each(function () {
				var option = $(this);
				$.getJSON(\'', get_option('siteurl'), '/wp-content/plugins/', WPACP_PLUGIN_DIR_NAME, '/json.php?cat=\' + option.val(), function(posts) {
					$(\'#category_posts\').append(\'<optgroup label="\' + option.text().replace(/\s*\(\d+\)/gi, \'\') + \'">\');

					$.each(posts, function(i, post){
						$(\'#category_posts\').append(\'<option value="\' + post.id + \'">\' + post.text + \'</option>\');
					});

					$(\'#category_posts\').append(\'</optgroup>\');
				});
			});
		};


json.php'den ilgili kısım:
$cat = !empty($_REQUEST['cat']) ? (int) $_REQUEST['cat'] : 1;

$request = $wpdb->get_results("
	SELECT ID, post_title 
	FROM {$wpdb->prefix}posts, {$wpdb->prefix}term_relationships, {$wpdb->prefix}term_taxonomy
	WHERE {$wpdb->prefix}posts.ID = {$wpdb->prefix}term_relationships.object_id
		AND {$wpdb->prefix}term_relationships.term_taxonomy_id = {$wpdb->prefix}term_taxonomy.term_taxonomy_id
		AND {$wpdb->prefix}term_taxonomy.taxonomy = 'category'
		AND {$wpdb->prefix}term_taxonomy.term_id = '{$cat}'
		AND {$wpdb->prefix}posts.post_type = 'post'");
$posts = array();
foreach ($request as $row) 
	$posts[] = array(
		'id' => $row->ID,
		'text' => $row->post_title
	);

echo json_encode ($posts);
+0
-0
Cevaba KatılıyorumKatılmıyorum
Cevap Yaz Yorum Yaz Arşivime Ekle Takip Et

Cevaplar

Hiç cevap bulunamadı. İlk cevabı siz yazın.