0

I want order my categories by hierarchy. But I want to use custom select name, id and class like this:

<select name="kategorisec" id="cat" class="postform">
...
</select>

and I want to use my custom value like this:

<option value="<?php echo $cat->slug; ?>"><?php echo $cat->name; ?></option>

But it doesn't ordering by hierarchy. How can I order the categories by hierarchy (with levels)? Thanks in advance. My all codes:

<?php $args2 = array(  
'taxonomy'     => 'fgaleri',    
'orderby'      => 'name', 
'show_count'   => 1,
'hierarchical' => 1,    
'title_li'     => ''  
);
?>
<?php $cats = get_categories($args2); ?>
<select name="kategorisec" id="cat" class="postform">
<option value="">Kategori Seç ve Ara</option>
<?php foreach ($cats as $cat) : ?>    
<option value="<?php echo $cat->slug; ?>">
<?php echo $cat->name; ?></option>  
<?php endforeach; ?>
1

I did! I found a function to make option value='slug'.

The function:

class SH_Walker_TaxonomyDropdown extends Walker_CategoryDropdown{
function start_el(&$output, $category, $depth, $args) {
    $pad = str_repeat('&nbsp;', $depth * 3);
    $cat_name = apply_filters('list_cats', $category->name, $category);
    if( !isset($args['value']) ){

        $args['value'] = ( $category->taxonomy != 'category' ? 'slug' : 'id' );
    }
    $value = ($args['value']=='slug' ? $category->slug : $category->term_id );
    $output .= "\t<option class=\"level-$depth\" value=\"".$value."\"";
    if ( $value === (string) $args['selected'] ){ 
        $output .= ' selected="selected"';
    }
    $output .= '>';
    $output .= $pad.$cat_name;
    if ( $args['show_count'] )
        $output .= '&nbsp;&nbsp;('. $category->count .')';
    $output .= "</option>\n";
    }
}

And my all codes:

<?php /** * Displays the Pagination in Custom loop * */?>
<?php get_header(); ?>
<?php global $wp_query;
$aranan= $_GET['s']; 
$kategorim = intval($_GET['cat']);
$kateg1= $_GET['kategorisec'];
if (intval($kateg1)<0) { $kateg = ""; } else { $kateg = $kateg1; }
$myterm = get_term( $kategorim, 'fgaleri' ); 
global $myslug;
$myslug = $myterm->slug; ?>
<div id="content">
<?php $rakam= 0;
//The query
$wp_query->query( array( 'post_type' =>'fotograf', 's' => $aranan, 'paged' => $paged, 'taxonomy' => 'fgaleri', 'fgaleri' => $kateg ) );
//The loop
?><div id="FGaleri_2"><div id="FGaleri_Ic"><div id="FGaleriBaslik">Fotoğraf Galerisi     <form action="<?php echo get_bloginfo('wpurl'); ?>" id="searchformfoto" method="get" name="searchform">
<?php $args = array( 'walker'=> new SH_Walker_TaxonomyDropdown(), 'class' => 'postform', 'id' => 'kategorisec', 'name' => 'kategorisec', 'value'=>'slug', 'taxonomy' => 'fgaleri', 'show_option_none' => 'Kategori Seç ve Ara', 'hierarchical' => 1 ); wp_dropdown_categories($args); ?>
<div id="aramabolumufoto">
<input name="s" id="sfoto" type="text" value=""/>
<input type="hidden" name="post_type" value="fotograf" />
<input id="searchsubmitfoto" type="submit" value="Ara"/>
</div></form></div>
<div class="FGaleri_Ic_2">
<?php while ($wp_query->have_posts()): $wp_query->the_post(); $rakam++; ?>
<div class="FGaleriItem2" style="<?php if ($rakam % 5 == 0 ) { ?>margin-right: 2px;<?php } ?>">
<?php 
$termargs=array('orderby' => 'count', 'order' => 'desc');
$terms = wp_get_post_terms( $post->ID , 'fgaleri', $termargs );
$t = count($terms);
if ($t>0) { ?>
<div class="fkategori">
<?php $c = 0;
foreach($terms as $term) {  
$c++;  
if ($c==$t)   
{   echo '<a class="foto_kategori" href="'. home_url() . '/?kategorisec=' . $term->slug . '&post_type=fotograf" title="' . $term->name . '" ' . '>' . $term->name.'</a> ';  }} ?>
</div><?php } ?>
<div class="ResimUst">
<?php if (has_post_thumbnail()) { ?>
<a href="<?php the_permalink() ?>">
<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );$url2 = get_bloginfo('template_directory') . "/timthumb.php?src=" . $url . "&amp;w=100&amp;h=100&amp;zc=1"; ?>
<img src="<?php if(get_option('of_timthumb')=="true") { echo $url2; } else { echo $url; } ?>" alt="" title="" width="100" height="100" /></a>
<?php } ?>
</div><div class="ResimAlt"><a href="<?php the_permalink() ?>">
<?php the_title(); ?>
</a></div></div>
<?php if (($rakam % 5 == 0 ) && ($rakam > 4)) { ?><div class="clearboth"></div><?php } ?>
<?php endwhile; ?></div></div></div><div class="clearboth"></div>
<?php if(function_exists('wp_pagenavi') ) {     
wp_pagenavi(); 
//function call for plugin pagination( wp pagenavi plugin)
} else { ?>     
<div id="navigasyon"><span class="previous-entries">
<?php next_posts_link('« Daha Eski Fotoğraflar'); ?></span>
<span class="next-entries"><?php previous_posts_link('Daha Yeni Fotoğraflar »'); ?></span>
</div><?php } //endif ?><?php ?></div><?php get_sidebar(); ?></div><?php get_footer(); ?>
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.