category menu type detail viewer

10 posts by 2 authors in: Forums > CMS Builder
Last Post: August 5, 2011   (RSS)

By buttermilk - August 3, 2011

Hello All,

I've got something that I'm pretty sure isn't too complicated, but I'm stumped.

My category menu is three levels deep: there is one "overview" section that is at depth "0" The main reserves.php list viewer displays the content of this overview along with links across the top for all records of depth "1". These links take the user to reservesDetail.php and display the information of all the depth "1" records. So far so good.
You can see the above here: http://74.52.72.36/~jocotoco/reserves.php

My problem is that on the reservesDetail.php page I'd like to have links across the top of the page to the associated depth "2" records. That is, it would look like the reserves.php page but with the third level links.
I'm almost there, I think: http://74.52.72.36/~jocotoco/reservesDetail.php?overview-tapichalaca-2

The header at the top of the reservesDetail.php page is as follows:




<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/jocotoco/public_html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records
list($reservesRecords, $reservesMetaData) = getRecords(array(
'tableName' => 'reserves',
'where' => whereRecordNumberInUrl(1),

));
$reservesRecord = @$reservesRecords[0]; // get first record

// show error message if no matching record is found
if (!$reservesRecord) {
header("HTTP/1.0 404 Not Found");
print "Record not found!";
exit;
}

?>


The php of the reservesDetail.php page is this:


<div class="content_main">

<h3 style="margin:0px;"><?php echo $reservesRecord['name'] ?></h3>

<div class="navigation_secondary">



<?php foreach ($reservesRecords as $record): ?>



<?php if ($reservesRecord['num'] != $record['num']): ?>


<div style="display:inline; margin-right:5px;"><a href="<?php echo $record['_link'] ?>"><?php echo $record['name'] ?></a></div>


<?php else: ?>

<div style="display:inline; margin-right:5px;"><?php echo $record['name'] ?></div>

<?php endif ?>

<?php endforeach ?>

</div>


<!-- STEP2: Display Records (Paste this where you want your records to be listed) -->

Record Number: <?php echo $reservesRecord['num'] ?><br/>
Parent Category: <?php echo $reservesRecord['parentNum'] ?><br/>
Name: <?php echo $reservesRecord['name'] ?><br/>
Content: <?php echo $reservesRecord['content'] ?><br/>
<!-- _link : <a href="<?php echo $reservesRecord['_link'] ?>"><?php echo $reservesRecord['_link'] ?></a><br/> -->


<!-- STEP 2a: Display Uploads for field 'images' (Paste this anywhere inside STEP2 to display uploads) -->

<?php foreach ($reservesRecord['images'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>

<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>

<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br/>

<?php endif ?>
<?php endforeach ?>
<!-- STEP2a: /Display Uploads -->


<hr/>
<?php if (!$reservesRecord): ?>
No record found!<br/><br/>
<?php endif ?>
<!-- /STEP2: Display Records -->

<a href="<?php echo $reservesMetaData['_listPage']; ?>">&lt;&lt; Back to OVERVIEW</a> -
<a href="mailto:?subject=<?php echo urlencode(thisPageUrl()) ?>">Email this Page</a>

</div>


Any help would be greatly appreciated.

Ian

Re: [buttermilk] category menu type detail viewer

By Jason - August 3, 2011

Hi Ian,

The issue you're having here is that your getRecords call will only ever return 1 record, which is why you're not getting all of the sub records you're looking for.

Try making this change to get all the sub categories of the selected category:

$reservesRecord = @$reservesRecords[0]; // get first record

// show error message if no matching record is found
if (!$reservesRecord) {
header("HTTP/1.0 404 Not Found");
print "Record not found!";
exit;
}

// get sub categories
list($navigationRecords, $selectedRecord) = getCategories(array(
'tableName' => 'reserves',
'rootCategoryNum' => $reservesRecord['num'],
));


Then change your foreach loop like this:

<div class="navigation_secondary">



<?php foreach ($navigationRecords as $record): ?>


Hope this helps get you started
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] category menu type detail viewer

By buttermilk - August 3, 2011 - edited: August 3, 2011

Hi Jason,

Thanks for helping me out!

That does indeed post the 3rd level links there.

A couple questions:

1. In the interests of learning, what exactly does that 'rootCategoryNum' do? How does that work?

2. I'd really like the second level depth link to be visible too. So, for instance, on this page (http://74.52.72.36/~jocotoco/reservesDetail.php?overview-tapichalaca-2) I'd like "tapichalaca" (depth 1) to be in front of the subsequent links.

3. When I click through to the subsections that your modification made appear, the links all disappear. Looking at the code, I can't understand why that is!
(http://74.52.72.36/~jocotoco/reservesDetail.php?overview-tapichalaca-Tapichalaca-subsection-2-13)

Ian

Re: [buttermilk] category menu type detail viewer

By buttermilk - August 3, 2011

Sorry, here's the new php:

<div class="navigation_secondary">



<?php foreach ($navigationRecords as $record): ?>



<?php if ($reservesRecord['num'] != $record['num']): ?>


<div style="display:inline; margin-right:5px;"><a href="<?php echo $record['_link'] ?>"><?php echo $record['name'] ?></a></div>


<?php else: ?>

<div style="display:inline; margin-right:5px;"><?php echo $record['name'] ?></div>

<?php endif ?>

<?php endforeach ?>

</div>

Re: [buttermilk] category menu type detail viewer

By Jason - August 3, 2011

Hi Ian,

if you set categoryRootNum, then the query will only return records descended from that number. So in our case, when you go to http://74.52.72.36/~jocotoco/reservesDetail.php?overview-tapichalaca-2 we are setting the number of tapicahalaca (2) as our root category and only returning records under it.

If you want to display the current category before the sub category links, try this:

<div class="navigation_secondary">

<div style="display:inline; margin-right:5px;"><a href="<?php echo $reservesRecord['_link'] ?>"><?php echo $reservesRecord['name'] ?></a></div>

<?php foreach ($navigationRecords as $record): ?>
<div style="display:inline; margin-right:5px;"><?php echo $record['name'] ?></div>

<?php endforeach ?>

</div>


Finally, the reason all the links are disappearing when you click on a 2nd level category (http://74.52.72.36/~jocotoco/reservesDetail.php?overview-tapichalaca-Tapichalaca-subsection-1-12) is because that category doesn't have any sub categories under it.

One way around this would be to show the sub categories on the same line as the current category when no sub categories are present.

Try this:
// get sub categories
list($navigationRecords, $selectedRecord) = getCategories(array(
'tableName' => 'reserves',
'rootCategoryNum' => $reservesRecord['num'],
));

$showRootCategory = true;

if (!$navitgationRecords) { // if there are no sub categories, revert to one level higher
list($navigationRecords, $selectedRecord) = getCategories(array(
'tableName' => 'reserves',
'rootCategoryNum' => $reservesRecord['parentNum'],
));

$showRootCategory = false;
}


Then change your output like this:

<div class="navigation_secondary">

<?php if ($showRootCategory): ?>
<div style="display:inline; margin-right:5px;"><a href="<?php echo $reservesRecord['_link'] ?>"><?php echo $reservesRecord['name'] ?></a></div>
<?php endif ?>

<?php foreach ($navigationRecords as $record): ?>

<?php if (!$showRootCategory && $reservesRecord['num'] == $record['num']): ?>
<div style="display:inline; margin-right:5px;"><a href="<?php echo $record['_link'] ?>"><?php echo $record['name'] ?></a></div>
<?php else: ?>
<div style="display:inline; margin-right:5px;"><?php echo $record['name'] ?></div>
<?php endif ?>

<?php endforeach ?>
</div>


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] category menu type detail viewer

By buttermilk - August 3, 2011 - edited: August 3, 2011

Ah, that's a useful function!

I switched up that code a bit and I'm really close! [:)] The only remaining problem is that the parent entry isn't visible in the subsections. Please, is there any way to include it?

You can see that when one clicks into the sub-sections of "Tapichalaca," the "Tapichalaca" link vanishes. I'd really like the user to be able to click back to that initial page. Is this possible?


http://74.52.72.36/~jocotoco/reservesDetail.php?overview-tapichalaca-2


Thanks for you patience, Jason.

header:

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/jocotoco/public_html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records
list($reservesRecords, $reservesMetaData) = getRecords(array(
'tableName' => 'reserves',
'where' => whereRecordNumberInUrl(1),

));
$reservesRecord = @$reservesRecords[0]; // get first record

// show error message if no matching record is found
if (!$reservesRecord) {
header("HTTP/1.0 404 Not Found");
print "Record not found!";
exit;
}

// get sub categories
list($navigationRecords, $selectedRecord) = getCategories(array(
'tableName' => 'reserves',
'rootCategoryNum' => $reservesRecord['num'],
));

$showRootCategory = true;

if (!$navigationRecords) { // if there are no sub categories, revert to one level higher
list($navigationRecords, $selectedRecord) = getCategories(array(
'tableName' => 'reserves',
'rootCategoryNum' => $reservesRecord['parentNum'],
));

$showRootCategory = false;
}

?>


PHP:

<div class="navigation_secondary">

<?php if ($showRootCategory): ?>
<div style="display:inline; margin-right:5px;"><?php echo $reservesRecord['name'] ?></div>
<?php endif ?>

<?php foreach ($navigationRecords as $record): ?>

<?php if (!$showRootCategory && $reservesRecord['num'] == $record['num']): ?>
<div style="display:inline; margin-right:5px;"><?php echo $record['name'] ?></div>
<?php else: ?>
<div style="display:inline; margin-right:5px;"><a href="<?php echo $record['_link'] ?>"><?php echo $record['name'] ?></a></div>
<?php endif ?>

<?php endforeach ?>
</div>


Ian

p.s. I've added a screenshot of the category menu in question.
Attachments:

reserves.jpg 132K

Re: [buttermilk] category menu type detail viewer

By Jason - August 4, 2011 - edited: August 5, 2011

Hi,

You can attempt to find a parent record like this:

// get sub categories
list($navigationRecords, $selectedRecord) = getCategories(array(
'tableName' => 'reserves',
'rootCategoryNum' => $reservesRecord['num'],
));

$showRootCategory = true;

if (!$navigationRecords) { // if there are no sub categories, revert to one level higher
list($navigationRecords, $selectedRecord) = getCategories(array(
'tableName' => 'reserves',
'rootCategoryNum' => $reservesRecord['parentNum'],
));

$showRootCategory = false;
}


$parent = array();

if ($reservesRecord['parentNum']) {
list($parentRecord,) = getRecords(array(
'tableName' => 'reserves',
'allowSearch' => false,
'where' => "num = '".intval($reservesRecord['parentNum'])."'",
));

if ($parentRecord) {
$parent = $parentRecord[0];
}
}



Then, if one was found, you can output like this:

<div class="navigation_secondary">


<?php if ($parent): ?>
<div style="display:inline; margin-right:5px;"><a href = "<?php echo $parent['_link'];?>"><?php echo $parent['name'] ?></a></div>
<?php endif ?>


<?php if ($showRootCategory): ?>
<div style="display:inline; margin-right:5px;"><?php echo $reservesRecord['name'] ?></div>
<?php endif ?>

<?php foreach ($navigationRecords as $record): ?>

<?php if (!$showRootCategory && $reservesRecord['num'] == $record['num']): ?>
<div style="display:inline; margin-right:5px;"><?php echo $record['name'] ?></div>
<?php else: ?>
<div style="display:inline; margin-right:5px;"><a href="<?php echo $record['_link'] ?>"><?php echo $record['name'] ?></a></div>
<?php endif ?>

<?php endforeach ?>
</div>


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] category menu type detail viewer

By buttermilk - August 4, 2011

It's so close I can taste it!

After a bit of trial and error I included an if statement to prevent the "overview" section from showing up (the 0 depth entry). This means my secondary navigation now looks like this:

<div class="navigation_secondary">

<?php if ($parent): ?>

<div style="display:inline; margin-right:5px;">

<?php if ($parent['depth'] == 1): ?>

<a href = "<?php $parent['_link'];?>"><?php echo $parent['name'] ?></a>

<?php endif ?>

</div>

<?php endif ?>


<?php if ($showRootCategory): ?>
<div style="display:inline; margin-right:5px;"><?php echo $reservesRecord['name'] ?></div>
<?php endif ?>

<?php foreach ($navigationRecords as $record): ?>

<?php if (!$showRootCategory && $reservesRecord['num'] == $record['num']): ?>
<div style="display:inline; margin-right:5px;"><?php echo $record['name'] ?></div>
<?php else: ?>
<div style="display:inline; margin-right:5px;"><a href="<?php echo $record['_link'] ?>"><?php echo $record['name'] ?></a></div>
<?php endif ?>

<?php endforeach ?>
</div>


So now the link is showing up exactly as I wanted, but it doesn't link to the right place. Argh!

So if you start here:
http://74.52.72.36/~jocotoco/reservesDetail.php?overview-Tapichalaca-2

and navigate to the subsections, the first "Tapichalaca" button remains, just as I need it to, but it doesn't point to the right place. It should point here:
http://74.52.72.36/~jocotoco/reservesDetail.php?overview-Tapichalaca-2
Instead, it points here:
http://74.52.72.36/~jocotoco/reservesDetail.php?overview-tapichalaca-Tapichalaca-subsection-1-12

This must be something to do with this code: <a href = "<?php $parent['_link'];?>"> If I understand correctly that link should go to the parent of the subsection, but for some reason it doesn't. [crazy]

Ian

[/url]

Re: [buttermilk] category menu type detail viewer

By Jason - August 5, 2011

Hi Ian,

We are extremely close. The error here is actually a common one (and I put it in the code...oops).

You're right, the issue is with this line:
<a href = "<?php $parent['_link'];?>">

Because we're not actually telling PHP to output the contents of $parent['_link'], the href has no value, which means it just reloads the page it's already on. We need to and in an echo statement like this:

<a href = "<?php echo $parent['_link'];?>">

That should take care of the issue.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/