AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein [PHP] Datensätze als Baum darstellen
Thema durchsuchen
Ansicht
Themen-Optionen

[PHP] Datensätze als Baum darstellen

Ein Thema von Matze · begonnen am 19. Feb 2008 · letzter Beitrag vom 2. Mär 2008
 
Benutzerbild von cruiser
cruiser

Registriert seit: 23. Dez 2003
Ort: Königsbrück/Sachsen
455 Beiträge
 
Delphi 7 Enterprise
 
#2

Re: [PHP] Datensätze als Baum darstellen

  Alt 19. Feb 2008, 18:57
Hallo...

ich nehm Wordpress für eine Website und da hab ichs fürs Menü auch so eine Struktur mit einer eignen Funktion geparsed... evtl. hilft dir das ja...

Code:
// special styled menu
function SahaPrintMenu($parent="0", $path=null, $level=0) {
global $wpdb;

if (! isset($path) ) {
$path = explode("/", $_SERVER["REQUEST_URI"]);
array_shift($path);
}

$actpath= "/";
if ($level > 0) {
$before = "<h3 class=\"level".$level."\">";
$after = "</h3>";
for ($i = 0; $i < $level; $i++) {
$actpath .= "$path[$i]/";
}
} else {
$before = "<h2>";
$after = "</h2>";
}

$nosubs = array(
0 => array("mitglieder", "galerien"),
1 => array("galerie-archiv")
); // end $nosubs

$query = "
SELECT post_title,post_name,id
FROM $wpdb->posts
WHERE post_type=\"page\"
AND post_parent=\"$parent\"
AND post_status=\"publish\"
ORDER BY menu_order
";

$result = $wpdb->get_results($query, ARRAY_A);

foreach ($result as $row) {
if (count($wpdb->get_results("SELECT id FROM $wpdb->posts WHERE post_parent=\"$row[id]\"", ARRAY_A))) {
// hat unterpunkte
if (isset($nosubs[$level])) {
// irgendwas soll keine unterpunkte haben
if (in_array($row[post_name], $nosubs[$level])) {
// dieses soll keine unterpunkte haben
if ($row[post_name] == $path[$level]) {
// aktuell
echo $before."<a class=\"currlink\" href=\"$actpath".$row[post_name]."\">".$row[post_title]."</a>".$after;
} else {
// nicht aktuell
echo $before."<a href=\"$actpath".$row[post_name]."\">".$row[post_title]."</a>".$after;
}
} else {
// dieses darf unterpunkte haben
if ($row[post_name] == $path[$level]) {
//aktuell
if (isset($path[$level + 1])) {
// pfad geht tiefer
echo $before."<a href=\"$actpath".$row[post_name]."\">".$row[post_title]."</a>".$after;
} else {
// pfad geht nicht tiefer
echo $before."<a class=\"currlink\" href=\"$actpath".$row[post_name]."\">".$row[post_title]."</a>".$after;
}
SahaPrintMenu($row[id], $path, $level + 1);
} else {
// nicht aktuell
echo $before."<a href=\"$actpath".$row[post_name]."\">".$row[post_title]."</a>".$after;
}
}
} else {
// alles soll Unterpunkte haben
if ($row[post_name] == $path[$level]) {
// aktuell
if (isset($path[$level + 1])) {
// pfad geht tiefer
echo $before."<a href=\"$actpath".$row[post_name]."\">".$row[post_title]."</a>".$after;
} else {
// pfad geht nicht tiefer
echo $before."<a class=\"currlink\" href=\"$actpath".$row[post_name]."\">".$row[post_title]."</a>".$after;
}
SahaPrintMenu($row[id], $path, $level + 1);
} else {
// nicht aktuell
echo $before."<a href=\"$actpath".$row[post_name]."\">".$row[post_title]."</a>".$after;
}
}
} else {
// hat keine unterpunkte
if ($row[post_name] == $path[$level]) {
// aktuell
echo $before."<a class=\"currlink\" href=\"$actpath".$row[post_name]."\">".$row[post_title]."</a>".$after;
} else {
// nicht aktuell
echo $before."<a href=\"$actpath".$row[post_name]."\">".$row[post_title]."</a>".$after;
}
}
}
}
zugegeben... ist jetzt seeeeehr WordPress-Spezifisch
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:55 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz