Re: [csdesign] Sub-categories Tutorial
I'm getting close, but obviously, I'm still missing something. The Recipes page does come up with categories and all the right recipes list to the right of those categories, however, there are 2 errors with each category:
http://www.aubriericheson.com/recipes.php
ERROR:
Notice: Undefined index: recipe_category in /home/content/a/u/b/aubrier/html/recipes.php on line 56 Notice: Undefined variable: articleCountByCategoryNum in /home/content/a/u/b/aubrier/html/recipes.php on line 56 )
__________________________________________________
ON THE RECIPES.PHP PAGE, HERE'S STEP 1 AND STEP 2 CODE:
// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/content/a/u/b/aubrier/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($recipe_categoriesRecords, $selectedCategory) = getCategories(array(
'tableName' => 'recipe_categories',
));
list($recipesRecords, $recipesMetaData) = getRecords(array(
'tableName' => 'recipes',
));
?>
STEP 2: (LINE 56 starts with <a href="?recipe_categories=..... )
<!--BEGIN PAGE CODE HERE-->
<table width="830" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top"> <h1>Browse Recipes by Category</h1>
<ul>
<li><a href="?">(View All)</a></li>
<?php foreach ($recipe_categoriesRecords as $categoryRecord): ?>
<?php echo $categoryRecord['_listItemStart'] ?>
<?php if ($categoryRecord['_isSelected']): ?><b><?php endif ?>
<a href="?recipe_categories=<?php echo $categoryRecord['num'] ?>"><?php echo $categoryRecord['name'] ?> (<?php echo $articleCountByCategoryNum[$categoryRecord['recipe_categories']] ?>)</a>
<?php if ($categoryRecord['_isSelected']): ?></b><?php endif ?>
<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endforeach ?> s
</ul></td>
<td align="left" valign="top"> </td>
<td align="left" valign="top">
<!-- STEP2: Display Records (Paste this where you want your records to be listed) -->
<h1>Browse Recipes by Title</h1>
<?php foreach ($recipesRecords as $record): ?>
<a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a><br/>
<?php endforeach ?>
<?php if (!$recipesRecords): ?>
No records were found!<br/><br/>
<?php endif ?>
<!-- /STEP2: Display Records -->
__________________________________________________
I added this to the recipeDetail.php page (not ending ?> tag for placement)
$rows = mysql_query_fetch_all_array("SELECT c.num, COUNT(*) FROM {$TABLE_PREFIX}articles a JOIN {$TABLE_PREFIX}categories c ON a.recipe_categories = c.num GROUP BY c.num");
$articleCountByCategoryNum = array_combine(array_pluck($rows, 0), array_pluck($rows, 1));
?>
I'm getting close, but obviously, I'm still missing something. The Recipes page does come up with categories and all the right recipes list to the right of those categories, however, there are 2 errors with each category:
http://www.aubriericheson.com/recipes.php
ERROR:
Notice: Undefined index: recipe_category in /home/content/a/u/b/aubrier/html/recipes.php on line 56 Notice: Undefined variable: articleCountByCategoryNum in /home/content/a/u/b/aubrier/html/recipes.php on line 56 )
__________________________________________________
ON THE RECIPES.PHP PAGE, HERE'S STEP 1 AND STEP 2 CODE:
// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/content/a/u/b/aubrier/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($recipe_categoriesRecords, $selectedCategory) = getCategories(array(
'tableName' => 'recipe_categories',
));
list($recipesRecords, $recipesMetaData) = getRecords(array(
'tableName' => 'recipes',
));
?>
STEP 2: (LINE 56 starts with <a href="?recipe_categories=..... )
<!--BEGIN PAGE CODE HERE-->
<table width="830" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top"> <h1>Browse Recipes by Category</h1>
<ul>
<li><a href="?">(View All)</a></li>
<?php foreach ($recipe_categoriesRecords as $categoryRecord): ?>
<?php echo $categoryRecord['_listItemStart'] ?>
<?php if ($categoryRecord['_isSelected']): ?><b><?php endif ?>
<a href="?recipe_categories=<?php echo $categoryRecord['num'] ?>"><?php echo $categoryRecord['name'] ?> (<?php echo $articleCountByCategoryNum[$categoryRecord['recipe_categories']] ?>)</a>
<?php if ($categoryRecord['_isSelected']): ?></b><?php endif ?>
<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endforeach ?> s
</ul></td>
<td align="left" valign="top"> </td>
<td align="left" valign="top">
<!-- STEP2: Display Records (Paste this where you want your records to be listed) -->
<h1>Browse Recipes by Title</h1>
<?php foreach ($recipesRecords as $record): ?>
<a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a><br/>
<?php endforeach ?>
<?php if (!$recipesRecords): ?>
No records were found!<br/><br/>
<?php endif ?>
<!-- /STEP2: Display Records -->
__________________________________________________
In the Admin > Section Editors > Recipes
General: Table name (cms_recipes)
Viewer URLs:
• list page url: recipes.php
• detail page url: recipeDetail.php
I did not add anything view urls to the Recipe Categories Editor.
__________________________________________________
http://www.aubriericheson.com/recipes.php
So on the main recipes page, it looks like it's trying to display the number of articles so when that works, that's perfect and each set of recipes is coming up - even with the errors.
when I click on a recipe in the right column, it's trying... I get the url with the title afterwards but get this error on a blank page:
MySQL Error: Table 'aubriedb.cms_articles' doesn't exist
example:
http://www.aubriericheson.com/recipeDetail.php?Cinnamon-Quinoa-Hot-Cereal-36
__________________________________________________
Okay, and I'm only throwing this easy on in there because I know it will take you a fraction of the time to tell me as it will for me to find it.
right now the ListPageFields for recipes.php is:
dragSortOrder, recipe_categories, title
If I want it to list first by recipe_categories, then drag order, then title (alphabetically, what's the correct working for A-Z DESC... or is that it?
thanks so much!! She has her content in - we're ready to launch on Sunday... hopefully. Thanks! Tina