Könnte mir jemand das erlären?
Ich habe jetzt noch andere Quellen nach Lösungen für dieses Problem durchsucht und bin auf diesen kryptischen Kommentar unter dieser Url http://trac.wordpress.org/ticket/1189 gestoßen:
Zitatcleared
Attached patch adds dropdown feature to wp_list_pages(). Usage:
wp_list_pages('style=dropdown');
First draft. Still rough.
Das ganze sieht so aus. Villeicht könnte mir jemand von euch erklären ob dieser Code funktionert bzw. wo ich diesen einsetzen soll.
Vielen Dank im voraus.
Diff
Ticket #1189: dropdown_pages.diff
Index: template-functions-post.php
===================================================================
--- template-functions-post.php (revision 2495)
+++ template-functions-post.php (working copy)
@@ -311,15 +311,18 @@
if (!isset($r['depth'])) $r['depth'] = 0;
if (!isset($r['show_date'])) $r['show_date'] = '';
if (!isset($r['child_of'])) $r['child_of'] = 0;
- if ( !isset($r['title_li']) ) $r['title_li'] = __('Pages');
+ if (!isset($r['title_li']) ) $r['title_li'] = __('Pages');
+ if (!isset($r['style'])) $r['style'] = 'list';
-
// Query pages.
$pages = & get_pages($args);
if ( $pages ) :
- if ( $r['title_li'] )
+ if ( $r['title_li'] && 'list' == $r['style'] )
echo '<li id="pagenav">' . $r['title_li'] . '<ul>';
+ else
+ echo "<select name='page_id'>\n";
+
// Now loop over all pages that were selected
$page_tree = Array();
foreach($pages as $page) {
@@ -350,8 +353,10 @@
// Output of the pages starting with child_of as the root ID.
// child_of defaults to 0 if not supplied in the query.
_page_level_out($r['child_of'],$page_tree, $r);
- if ( $r['title_li'] )
+ if ( $r['title_li'] && 'list' == $r['style'] )
echo '[/list]';
+ else
+ echo "</select>\n";
endif;
}
@@ -360,39 +365,53 @@
$queried_obj = $wp_query->get_queried_object();
- if($depth)
+ if ($depth) {
$indent = str_repeat("\t", $depth);
- //$indent = join('', array_fill(0,$depth,"\t"));
+ $pad = str_repeat('', $depth * 3);
+ }
foreach($page_tree[$parent]['children'] as $page_id) {
$cur_page = $page_tree[$page_id];
$title = $cur_page['title'];
- $css_class = 'page_item';
- if( $page_id == $queried_obj->ID) {
- $css_class .= ' current_page_item';
- }
-
- echo $indent . '<li class="' . $css_class . '">[url="' . get_page_link($page_id) . '"]' . $title . '[/url]';
-
- if(isset($cur_page['ts'])) {
- $format = get_settings('date_format');
+ if ('list' == $args['style']) {
+ $css_class = 'page_item';
+ if( $page_id == $queried_obj->ID) {
+ $css_class .= ' current_page_item';
+ }
+
+ echo $indent . '<li class="' . $css_class . '">[url="' . get_page_link($page_id) . '"]' . $title . '[/url]';
+
+ if(isset($cur_page['ts'])) {
+ $format = get_settings('date_format');
if(isset($args['date_format']))
$format = $args['date_format'];
echo " " . mysql2date($format,$cur_page['ts']);
- }
- echo "\n";
-
- if(isset($cur_page['children']) && is_array($cur_page['children'])) {
- $new_depth = $depth + 1;
-
- if(!$args['depth'] || $depth < ($args['depth']-1)) {
- echo "$indent<ul>\n";
- _page_level_out($page_id,$page_tree, $args, $new_depth);
- echo "$indent[/list]\n";
}
+ echo "\n";
+
+ if(isset($cur_page['children']) && is_array($cur_page['children'])) {
+ $new_depth = $depth + 1;
+
+ if(!$args['depth'] || $depth < ($args['depth']-1)) {
+ echo "$indent<ul>\n";
+ _page_level_out($page_id, $page_tree, $args, $new_depth);
+ echo "$indent[/list]\n";
+ }
+ }
+ echo "$indent\n";
+ } elseif ('dropdown' == $args['style']) {
+ echo "\t<option value=\"".$page_id."\"";
+ if ($page_id == $queried_obj->ID)
+ echo ' selected="selected"';
+ echo '>';
+ echo "$pad$title";
+ echo "</option>\n";
+ if(isset($cur_page['children']) && is_array($cur_page['children'])) {
+ $new_depth = $depth + 1;
+ _page_level_out($page_id, $page_tree, $args, $new_depth);
+ }
}
- echo "$indent\n";
}
}
Alles anzeigen