Take a look at my code. As you probaly figured out it genereates a drop down menu (as seen in previous post) containting the document tree.
This menu pop up when you create new or edit articles. However, when you edit an article I want it’s parent to be selected in the menu.
Still with me?

I’m totally lost here since I don’t know what if statement is correct.
<?php
$table = $modx->getFullTableName("site_content");
$sql_result = $modx->db->select("id, pagetitle, parent", $table, "isfolder = 1 AND pagetitle <> 'Admin'", "menuindex DESC");
if(mysql_num_rows($sql_result)) {
echo "<option value='0'>Huvudmeny</option>";
while ($row = mysql_fetch_assoc($sql_result)) {
$cid = $row['id'];
$pdata = $modx->getParent($cid,1,'id');
$pid = $pdata['id'];
if($pid == "") {
$pid = "0";
}
if ($row['id'] == $pid) {
$selected = " selected";
} else {
$selected = "";
}
echo "<option value='".$row['id']."'".$selected."> ".$row['pagetitle']."</option>";
}
}
else {
echo "<option value='0'>Root</option>";
}
?>
I’m a terrible coder, I know. Nevertheless, I think I’ll publish my reworked version of NewsManager & NewsEditor when it’s finished