Wie zeige ich eine hierarchische Begriffsliste?
-
-
Fallsjemandeine hierarchische CHECKLISTEbenötigt (nicht die Frage hier,sondernfür Personen,dieeine benutzerdefinierte Benutzeroberflächefür hierarchische Taxonomienerstellen),ist diebeste Antwort,wp_terms_checklist ()mit Ihrerbenutzerdefinierten Taxonomie zu verwenden.In case anyone needs a hierarchical CHECKLIST (not the question here but related for people building custom UI for hierarchical taxonomies), the best answer is to use wp_terms_checklist() with your custom taxonomy.
- 2
- 2016-02-23
- jerclarke
-
11 Antworten
- Stimmen
-
- 2011-04-13
Verwenden Sie
wp_list_categories
mit dem'taxonomy' => 'taxonomy'
dient zum Erstellen hierarchischer Kategorielisten,unterstütztjedoch auch die Verwendungeinerbenutzerdefinierten Taxonomie.Codex-Beispiel:
Begriffein einerbenutzerdefinierten Taxonomie anzeigenWenn die Liste wiederflach aussieht,benötigen Siemöglicherweisenurein wenig CSS,um die Listen aufzufüllen,damit Sieihre hierarchische Struktur sehen können.
Use
wp_list_categories
with the'taxonomy' => 'taxonomy'
argument, it's built for creating hierarchical category lists but will also support using a custom taxonomy..Codex Example:
Display terms in a custom taxonomyIf the list comes back looking flat, it's possible you just need a little CSS to add padding to the lists, so you can see their hierarchical structure.
-
Könnte dies umgekehrt werden?Kinder zuerst anzeigen ..Could this be reversed? Display children first..
- 0
- 2016-03-06
- Arg Geo
-
- 2013-05-15
Mirist klar,dass dieseine sehr alte Frageist,aber wenn Sieeine tatsächliche Struktur von Begriffen aufbauenmüssen,ist diesmöglicherweiseeine nützliche Methodefür Sie:
/** * Recursively sort an array of taxonomy terms hierarchically. Child categories will be * placed under a 'children' member of their parent term. * @param Array $cats taxonomy term objects to sort * @param Array $into result array to put them in * @param integer $parentId the current parent ID to put them in */ function sort_terms_hierarchically(Array &$cats, Array &$into, $parentId = 0) { foreach ($cats as $i => $cat) { if ($cat->parent == $parentId) { $into[$cat->term_id] = $cat; unset($cats[$i]); } } foreach ($into as $topCat) { $topCat->children = array(); sort_terms_hierarchically($cats, $topCat->children, $topCat->term_id); } }
Die Verwendungist wiefolgt:
$categories = get_terms('my_taxonomy_name', array('hide_empty' => false)); $categoryHierarchy = array(); sort_terms_hierarchically($categories, $categoryHierarchy); var_dump($categoryHierarchy);
I realize, this is a very old question, but if you have a need to build up an actual structure of terms, this might be a useful method for you:
/** * Recursively sort an array of taxonomy terms hierarchically. Child categories will be * placed under a 'children' member of their parent term. * @param Array $cats taxonomy term objects to sort * @param Array $into result array to put them in * @param integer $parentId the current parent ID to put them in */ function sort_terms_hierarchically(Array &$cats, Array &$into, $parentId = 0) { foreach ($cats as $i => $cat) { if ($cat->parent == $parentId) { $into[$cat->term_id] = $cat; unset($cats[$i]); } } foreach ($into as $topCat) { $topCat->children = array(); sort_terms_hierarchically($cats, $topCat->children, $topCat->term_id); } }
Usage is as follows:
$categories = get_terms('my_taxonomy_name', array('hide_empty' => false)); $categoryHierarchy = array(); sort_terms_hierarchically($categories, $categoryHierarchy); var_dump($categoryHierarchy);
-
Dasisteigentlich richtiggut.Ich würdeeines ändern: `$in [$ cat->term_id]=$ cat;`in `$in []=$ cat;` Die ID des Begriffs als Array-Schlüssel zu habenist ärgerlich (Sie könnennichtbekommendaserste Elementeinfachmit der 0-Taste) undnutzlos (Sie speichernbereits das Objekt $ cat und können die IDmit der Eigenschaft `term_id` abrufen.This is actually really good. I would change one thing: `$into[$cat->term_id] = $cat;` into `$into[] = $cat;` Having the ID of the term as the array key is annoying (you can't get the first element easily using the 0 key) and useless (you're already storing the `$cat` object and you can get the id using the `term_id` property.
- 3
- 2017-03-07
- Nahuel
-
Wenn Sie wieich versuchen,diese Funktion aufeine Unterebene von Kategorien anzuwenden,müssen Sie die ID der Ebene übergeben,auf der Sie sichgeradebefinden,damit diesfunktioniert.Aberesfunktioniertgut,danke @popsi.If like me you're trying to apply this function to a sub-level of categories, you will need to pass in the ID of the level you're currently at for this to work. But work nicely it does, thanks @popsi.
- 0
- 2018-08-16
- Ben Everard
-
dasfunktioniert,dankethat works, thank you
- 0
- 2019-11-12
- Luca Reghellin
-
- 2011-04-13
Ich kenne keine Funktion,die dastut,was Sie wollen,aber Sie können soetwas aufbauen:
<ul> <?php $hiterms = get_terms("my_tax", array("orderby" => "slug", "parent" => 0)); ?> <?php foreach($hiterms as $key => $hiterm) : ?> <li> <?php echo $hiterm->name; ?> <?php $loterms = get_terms("my_tax", array("orderby" => "slug", "parent" => $hiterm->term_id)); ?> <?php if($loterms) : ?> <ul> <?php foreach($loterms as $key => $loterm) : ?> <li><?php echo $loterm->name; ?></li> <?php endforeach; ?> </ul> <?php endif; ?> </li> <?php endforeach; ?> </ul>
Ich habe dasnichtgetestet,aber Sie können sehen,woraufich hinaus will. Mit dem obigen Codeerhalten Sienur zwei Ebenen
BEARBEITEN: ahhja,Sie können wp_list_categories () verwenden,um das zutun,wonach Sie suchen.
I dont know of any function that does what you want but you can build up something like this:
<ul> <?php $hiterms = get_terms("my_tax", array("orderby" => "slug", "parent" => 0)); ?> <?php foreach($hiterms as $key => $hiterm) : ?> <li> <?php echo $hiterm->name; ?> <?php $loterms = get_terms("my_tax", array("orderby" => "slug", "parent" => $hiterm->term_id)); ?> <?php if($loterms) : ?> <ul> <?php foreach($loterms as $key => $loterm) : ?> <li><?php echo $loterm->name; ?></li> <?php endforeach; ?> </ul> <?php endif; ?> </li> <?php endforeach; ?> </ul>
I haven't tested this but you can see what I'm getting at. What the above code will do is give you only two levels
EDIT: ahh yes you can use wp_list_categories() to do what you after.
-
Eigentlichist dies sehrnützlich,daichbenutzerdefinierte Links (miteinem GET-Parameter)für den Begriff Links habenmuss,wasmit der Methode wp_list_categories ()nichtmöglich zu sein scheint.Actually this is quite useful, as I need to have custom links (with a GET param) on the term links, which doesn't seem possible with the wp_list_categories() way of doing it.
- 0
- 2011-04-13
- mike23
-
Ja,diese Methodegibt Ihnenmehr Kontrolle über Ihre Ausgabe.Sie könnenjedoch die Ausgabe von "wp_list_categories ()"ein wenig suchen undersetzen,um Ihre GET-Parameter hinzuzufügen.Odererstellen Sienochbessereinen Filterfür die Funktion,um diegewünschten Bits hinzuzufügen.Fragen Siemichnicht,wie Sie dasmachen,daichesnochnicht verstanden habe :(Yes this method will give more control over your output. But you could do some nice bit of find and replace on the output of `wp_list_categories()` to add in your GET parameters. Or even better build a filter for the function to add in the bits you want. Don't ask me how you do that as I've not yet been able to get my head around it :(
- 1
- 2011-04-13
- Scott
-
Ich würde vorschlagen,einen [benutzerdefinierten Kategorie-Walker] (http://www.google.co.uk/search?q=wordpres+custom+category+walker)mit `wp_list_categories` zu verwenden,wenn Sieeine bessere Kontrolle über die Ausgabe wünschenIch werde Ihren Code viel wiederverwendbarermachen.I'd suggest using a [custom category walker](http://www.google.co.uk/search?q=wordpres+custom+category+walker) with `wp_list_categories` if you want greater control over the output, it'll make your code much more reusable..
- 3
- 2011-04-13
- t31os
-
-
- 2016-01-13
Derfolgende Codegeneriertein Dropdown-Menümit Begriffen,kann aber auchjedes andere Element/jede andere Strukturgenerieren,indem Sie die Variable $ outputTemplatebearbeiten und die Zeilen str_replacebearbeiten:
function get_terms_hierarchical($terms, $output = '', $parent_id = 0, $level = 0) { //Out Template $outputTemplate = '<option value="%ID%">%PADDING%%NAME%</option>'; foreach ($terms as $term) { if ($parent_id == $term->parent) { //Replacing the template variables $itemOutput = str_replace('%ID%', $term->term_id, $outputTemplate); $itemOutput = str_replace('%PADDING%', str_pad('', $level*12, ' '), $itemOutput); $itemOutput = str_replace('%NAME%', $term->name, $itemOutput); $output .= $itemOutput; $output = get_terms_hierarchical($terms, $output, $term->term_id, $level + 1); } } return $output; } $terms = get_terms('taxonomy', array('hide_empty' => false)); $output = get_terms_hierarchical($terms); echo '<select>' . $output . '</select>';
The following code will generate drop-down with terms, but also can generate any other element/structure by editing the $outputTemplate variable, and editing str_replace lines:
function get_terms_hierarchical($terms, $output = '', $parent_id = 0, $level = 0) { //Out Template $outputTemplate = '<option value="%ID%">%PADDING%%NAME%</option>'; foreach ($terms as $term) { if ($parent_id == $term->parent) { //Replacing the template variables $itemOutput = str_replace('%ID%', $term->term_id, $outputTemplate); $itemOutput = str_replace('%PADDING%', str_pad('', $level*12, ' '), $itemOutput); $itemOutput = str_replace('%NAME%', $term->name, $itemOutput); $output .= $itemOutput; $output = get_terms_hierarchical($terms, $output, $term->term_id, $level + 1); } } return $output; } $terms = get_terms('taxonomy', array('hide_empty' => false)); $output = get_terms_hierarchical($terms); echo '<select>' . $output . '</select>';
-
- 2013-02-21
Daichnach demgleichengesucht habe,aber um die Bedingungenfüreinen Beitrag zuerhalten,habeich diesen schließlich kompiliert underfunktioniertfürmich.
Wasestut:
• Es werden alle Begriffeeines Taxonomienamensfüreinen bestimmten Beitrag abgerufen.
• Füreine hierachische Taxonomiemit zwei Ebenen (z. B. Ebene 1: 'Land' und Ebene 2: 'Städte') wirdein h4mit der Ebene 1erstellt,gefolgt voneiner ul-Liste der Ebene 2 und diesfür alle Elemente der Ebene 1.
• Wenn die Taxonomienicht hierarchischist,wirdnureine ul-Liste aller Elementeerstellt. Hierist der Code (ich schreibeihnfürmich,also habeich versucht,so allgemein wiemöglich zu sein,aber ...):
function finishingLister($heTerm){ $myterm = $heTerm; $terms = get_the_terms($post->ID,$myterm); if($terms){ $count = count($terms); echo '<h3>'.$myterm; echo ((($count>1)&&(!endswith($myterm, 's')))?'s':"").'</h3>'; echo '<div class="'.$myterm.'Wrapper">'; foreach ($terms as $term) { if (0 == $term->parent) $parentsItems[] = $term; if ($term->parent) $childItems[] = $term; }; if(is_taxonomy_hierarchical( $heTerm )){ foreach ($parentsItems as $parentsItem){ echo '<h4>'.$parentsItem->name.'</h4>'; echo '<ul>'; foreach($childItems as $childItem){ if ($childItem->parent == $parentsItem->term_id){ echo '<li>'.$childItem->name.'</li>'; }; }; echo '</ul>'; }; }else{ echo '<ul>'; foreach($parentsItems as $parentsItem){ echo '<li>'.$parentsItem->name.'</li>'; }; echo '</ul>'; }; echo '</div>'; }; };
Schließlich rufen Sie die Funktion damit auf (offensichtlichersetzen Siemy_taxonomy durch Ihre):
finishingLister('my_taxonomy');
Ichtuenicht so,als wäreesperfekt,aber wiegesagt,esfunktioniertbei mir.
As I was looking for the same but to get terms of one post, finally I compiled this, and it works for me.
What it does :
• it gets all terms of a taxonomy name for a specific post.
• for a hierachical taxonomy with two levels (ex: level1:'country' and level2:'cities'), it creates a h4 with the level1 followed by an ul list of level2 and this for all level1 items.
• if the taxonomy is not hierarchical, it will create only an ul list of all items. here is the code (I write it for me so I tried to be as generic as I can but...) :function finishingLister($heTerm){ $myterm = $heTerm; $terms = get_the_terms($post->ID,$myterm); if($terms){ $count = count($terms); echo '<h3>'.$myterm; echo ((($count>1)&&(!endswith($myterm, 's')))?'s':"").'</h3>'; echo '<div class="'.$myterm.'Wrapper">'; foreach ($terms as $term) { if (0 == $term->parent) $parentsItems[] = $term; if ($term->parent) $childItems[] = $term; }; if(is_taxonomy_hierarchical( $heTerm )){ foreach ($parentsItems as $parentsItem){ echo '<h4>'.$parentsItem->name.'</h4>'; echo '<ul>'; foreach($childItems as $childItem){ if ($childItem->parent == $parentsItem->term_id){ echo '<li>'.$childItem->name.'</li>'; }; }; echo '</ul>'; }; }else{ echo '<ul>'; foreach($parentsItems as $parentsItem){ echo '<li>'.$parentsItem->name.'</li>'; }; echo '</ul>'; }; echo '</div>'; }; };
So finally you call the function with this (obviously, you replace my_taxonomy by yours) :
finishingLister('my_taxonomy');
I don't pretend it's perfect but as I said it works for me.
-
- 2013-11-30
Ich hatte dieses Problem und keine der Antworten hier hat aus demeinen oder anderen Grundfürmichfunktioniert.
Hieristmeine aktualisierte undfunktionierende Version.
function locationSelector( $fieldName ) { $args = array('hide_empty' => false, 'hierarchical' => true, 'parent' => 0); $terms = get_terms("locations", $args); $html = ''; $html .= '<select name="' . $fieldName . '"' . 'class="chosen-select ' . $fieldName . '"' . '>'; foreach ( $terms as $term ) { $html .= '<option value="' . $term->term_id . '">' . $term->name . '</option>'; $args = array( 'hide_empty' => false, 'hierarchical' => true, 'parent' => $term->term_id ); $childterms = get_terms("locations", $args); foreach ( $childterms as $childterm ) { $html .= '<option value="' . $childterm->term_id . '">' . $term->name . ' > ' . $childterm->name . '</option>'; $args = array('hide_empty' => false, 'hierarchical' => true, 'parent' => $childterm->term_id); $granchildterms = get_terms("locations", $args); foreach ( $granchildterms as $granchild ) { $html .= '<option value="' . $granchild->term_id . '">' . $term->name . ' > ' . $childterm->name . ' > ' . $granchild->name . '</option>'; } } } $html .= "</select>"; return $html; }
Und Verwendung:
$selector = locationSelector('locationSelectClass'); echo $selector;
I had this problem and none of the answers here worked for me, for one reason or another.
Here is my updated and working version.
function locationSelector( $fieldName ) { $args = array('hide_empty' => false, 'hierarchical' => true, 'parent' => 0); $terms = get_terms("locations", $args); $html = ''; $html .= '<select name="' . $fieldName . '"' . 'class="chosen-select ' . $fieldName . '"' . '>'; foreach ( $terms as $term ) { $html .= '<option value="' . $term->term_id . '">' . $term->name . '</option>'; $args = array( 'hide_empty' => false, 'hierarchical' => true, 'parent' => $term->term_id ); $childterms = get_terms("locations", $args); foreach ( $childterms as $childterm ) { $html .= '<option value="' . $childterm->term_id . '">' . $term->name . ' > ' . $childterm->name . '</option>'; $args = array('hide_empty' => false, 'hierarchical' => true, 'parent' => $childterm->term_id); $granchildterms = get_terms("locations", $args); foreach ( $granchildterms as $granchild ) { $html .= '<option value="' . $granchild->term_id . '">' . $term->name . ' > ' . $childterm->name . ' > ' . $granchild->name . '</option>'; } } } $html .= "</select>"; return $html; }
And usage:
$selector = locationSelector('locationSelectClass'); echo $selector;
-
- 2018-07-09
Ich habe @popsi-Code verwendet,der wirklichgutfunktioniert hat,undich habeihneffizienter undeinfacher zu lesengemacht:
/** * Recursively sort an array of taxonomy terms hierarchically. Child categories will be * placed under a 'children' member of their parent term. * @param Array $cats taxonomy term objects to sort * @param integer $parentId the current parent ID to put them in */ function sort_terms_hierarchicaly(Array $cats, $parentId = 0) { $into = []; foreach ($cats as $i => $cat) { if ($cat->parent == $parentId) { $cat->children = sort_terms_hierarchicaly($cats, $cat->term_id); $into[$cat->term_id] = $cat; } } return $into; }
Verwendung:
$sorted_terms = sort_terms_hierarchicaly($terms);
I used @popsi code that was working really well and I made it a more efficient and easy to read:
/** * Recursively sort an array of taxonomy terms hierarchically. Child categories will be * placed under a 'children' member of their parent term. * @param Array $cats taxonomy term objects to sort * @param integer $parentId the current parent ID to put them in */ function sort_terms_hierarchicaly(Array $cats, $parentId = 0) { $into = []; foreach ($cats as $i => $cat) { if ($cat->parent == $parentId) { $cat->children = sort_terms_hierarchicaly($cats, $cat->term_id); $into[$cat->term_id] = $cat; } } return $into; }
Usage :
$sorted_terms = sort_terms_hierarchicaly($terms);
-
- 2020-05-04
Diese Lösungist wenigereffizient als der Code von @popsi,dafürjeden Begriffeine neue Abfrageerstellt wird,die Verwendungin einer Vorlagejedoch aucheinfacherist. Wenn Ihre Website Caching verwendet,können Sie,wieich,dengeringen Datenbankaufwandnicht stören.
Siemüssen kein Array vorbereiten,das rekursivmit Begriffengefüllt wird. Sienennen eseinfach so,wie Sie get_terms () (das Nicht-)nennen würden. veraltetes Formularmit nureinem Arrayfürein Argument). Esgibt ein Array von
WP_Term
-Objektenmit einer zusätzlichen Eigenschaftnamenschildren
zurück.function get_terms_tree( Array $args ) { $new_args = $args; $new_args['parent'] = $new_args['parent'] ?? 0; $new_args['fields'] = 'all'; // The terms for this level $terms = get_terms( $new_args ); // The children of each term on this level foreach( $terms as &$this_term ) { $new_args['parent'] = $this_term->term_id; $this_term->children = get_terms_tree( $new_args ); } return $terms; }
Die Verwendungisteinfach:
$terms = get_terms_tree([ 'taxonomy' => 'my-tax' ]);
This solution is less efficient than @popsi's code, since it makes a new query for every term, but it's also easier to use in a template. If your website uses caching, you may, like me, not mind the slight database overhead.
You don't need to prepare an array that'll be recursively filled with terms. You just call it the same way you would call get_terms() (the non-deprecated form with only an array for an argument). It returns an array of
WP_Term
objects with an extra property calledchildren
.function get_terms_tree( Array $args ) { $new_args = $args; $new_args['parent'] = $new_args['parent'] ?? 0; $new_args['fields'] = 'all'; // The terms for this level $terms = get_terms( $new_args ); // The children of each term on this level foreach( $terms as &$this_term ) { $new_args['parent'] = $this_term->term_id; $this_term->children = get_terms_tree( $new_args ); } return $terms; }
Usage is simple:
$terms = get_terms_tree([ 'taxonomy' => 'my-tax' ]);
-
- 2011-04-13
Stellen Sie sicher,dass
hierarchical=true
an Ihreget_terms()
anrufen.Beachten Sie,dass
hierarchical=true
die Standardeinstellungist. Stellen Sie also sicher,dassesnicht überschrieben wurde,umfalse
zu sein.Be sure that
hierarchical=true
is passed to yourget_terms()
call.Note that
hierarchical=true
is the default, so really, just be sure that it hasn't been overridden to befalse
.-
Hallo Chip,ja 'hierarchisch'ist standardmäßig 'wahr'.Hi Chip, yes 'hierarchical' is 'true' by default.
- 0
- 2011-04-13
- mike23
-
Können Sieeinen Link zueinem Live-Beispiel der Ausgabebereitstellen?Can you provide a link to a live example of the output?
- 0
- 2011-04-13
- Chip Bennett
-
Eine Antwort kommentieren,die vorfast zwei Jahren hinterlassen wurde?"Ja wirklich?"Eigentlichisteseine vorgeschlagene Antwort,auch wenn sie als Frageformuliertist.Solliches sobearbeiten,dassesehereine Aussage alseine Frageist?Commenting on an answer left almost two years ago? Really? Actually, it *is* a proposed answer, even if worded as a question. Shall I edit it to be a statement, rather than a question?
- 0
- 2013-02-11
- Chip Bennett
-
`get_terms ()`gibt eine vollständige Liste der Begriffe zurück (wieim OP angegeben),jedoch keine hierarchische Liste,in der die angeforderte Eltern-Kind-Beziehung angezeigt wird.`get_terms()` will return a full list of the terms (as the OP stated) but not a hierarchical list showing parent / child relationship as requested.
- 0
- 2016-03-17
- jdm2112
-
- 2013-03-25
Hier habeicheine Dropdown-Auswahllistemit vier Ebenen und verstecktemersten Element
<select name="lokalizacja" id="ucz"> <option value="">Wszystkie lokalizacje</option> <?php $excluded_term = get_term_by('slug', 'podroze', 'my_travels_places'); $args = array( 'orderby' => 'slug', 'hierarchical' => 'true', 'exclude' => $excluded_term->term_id, 'hide_empty' => '0', 'parent' => $excluded_term->term_id, ); $hiterms = get_terms("my_travels_places", $args); foreach ($hiterms AS $hiterm) : echo "<option value='".$hiterm->slug."'".($_POST['my_travels_places'] == $hiterm->slug ? ' selected="selected"' : '').">".$hiterm->name."</option>\n"; $loterms = get_terms("my_travels_places", array("orderby" => "slug", "parent" => $hiterm->term_id,'hide_empty' => '0',)); if($loterms) : foreach($loterms as $key => $loterm) : echo "<option value='".$loterm->slug."'".($_POST['my_travels_places'] == $loterm->slug ? ' selected="selected"' : '')."> - ".$loterm->name."</option>\n"; $lo2terms = get_terms("my_travels_places", array("orderby" => "slug", "parent" => $loterm->term_id,'hide_empty' => '0',)); if($lo2terms) : foreach($lo2terms as $key => $lo2term) : echo "<option value='".$lo2term->slug."'".($_POST['my_travels_places'] == $lo2term->slug ? ' selected="selected"' : '')."> - ".$lo2term->name."</option>\n"; endforeach; endif; endforeach; endif; endforeach; ?> </select> <label>Wybierz rodzaj miejsca</label> <select name="rodzaj_miejsca" id="woj"> <option value="">Wszystkie rodzaje</option> <?php $theterms = get_terms('my_travels_places_type', 'orderby=name'); foreach ($theterms AS $term) : echo "<option value='".$term->slug."'".($_POST['my_travels_places_type'] == $term->slug ? ' selected="selected"' : '').">".$term->name."</option>\n"; endforeach; ?> </select>
Here I have four level dropdown select list with hidden first item
<select name="lokalizacja" id="ucz"> <option value="">Wszystkie lokalizacje</option> <?php $excluded_term = get_term_by('slug', 'podroze', 'my_travels_places'); $args = array( 'orderby' => 'slug', 'hierarchical' => 'true', 'exclude' => $excluded_term->term_id, 'hide_empty' => '0', 'parent' => $excluded_term->term_id, ); $hiterms = get_terms("my_travels_places", $args); foreach ($hiterms AS $hiterm) : echo "<option value='".$hiterm->slug."'".($_POST['my_travels_places'] == $hiterm->slug ? ' selected="selected"' : '').">".$hiterm->name."</option>\n"; $loterms = get_terms("my_travels_places", array("orderby" => "slug", "parent" => $hiterm->term_id,'hide_empty' => '0',)); if($loterms) : foreach($loterms as $key => $loterm) : echo "<option value='".$loterm->slug."'".($_POST['my_travels_places'] == $loterm->slug ? ' selected="selected"' : '')."> - ".$loterm->name."</option>\n"; $lo2terms = get_terms("my_travels_places", array("orderby" => "slug", "parent" => $loterm->term_id,'hide_empty' => '0',)); if($lo2terms) : foreach($lo2terms as $key => $lo2term) : echo "<option value='".$lo2term->slug."'".($_POST['my_travels_places'] == $lo2term->slug ? ' selected="selected"' : '')."> - ".$lo2term->name."</option>\n"; endforeach; endif; endforeach; endif; endforeach; ?> </select> <label>Wybierz rodzaj miejsca</label> <select name="rodzaj_miejsca" id="woj"> <option value="">Wszystkie rodzaje</option> <?php $theterms = get_terms('my_travels_places_type', 'orderby=name'); foreach ($theterms AS $term) : echo "<option value='".$term->slug."'".($_POST['my_travels_places_type'] == $term->slug ? ' selected="selected"' : '').">".$term->name."</option>\n"; endforeach; ?> </select>
-
Bitteerklären Sie ** warum ** das das Problem lösen könnte.Please explain **why** that could solve the problem.
- 2
- 2013-03-25
- fuxia
-
Ich denke,die Logikist,dassesein verwandtes Problemist.Ich habe diesen Beitraggefunden,um herauszufinden,wiemaneine hierarchische Checklisteim Kategoriestilerhält,undbin versucht,hiereine Antwort hinzuzufügen,nachdemiches herausgefunden habe.Ich werdees abernichttun,weiles,wie Siebetonen,den OQnichtbeantwortet.I think the logic is that it's a related problem. I found this post trying to figure out how to get a category-style hierarchical checklist and am tempted to add an answer here now that I've figured it out. I won't though because as you point out it doesn't answer the OQ.
- 0
- 2016-02-23
- jerclarke
Ich habeeine hierarchische Taxonomienamens "geografische Standorte".Esenthält Kontinente aufeinerersten Ebene und dann die Länderfürjeden.Beispiel:
usw.
Mitget_terms () konnteich die vollständige Liste der Begriffe ausgeben,aber die Kontinente werdenmit den Ländernin einergroßenflachen Liste verwechselt.
Wie kannicheine hierarchische Liste wie oben ausgeben?