Page Templates:Creating a Category Template
From Whirlwind eCommerce Wiki
|
Create a category template
Creating a category template is very similar to creating a basic template, with the addition of children. Children are a list of homogeneous items, controlled by relationships in page management, that appear inside of a page. Children are synonimous with subcategories that are displayed in a category page, product pages that are displayed in a sub category pate, photos that are displayed in a photo album page, cross sell product pages that appear in a product page, etc. Children are assigned to a page using relationship management in page management. Those assigned children (and associated data) are accessible via the pageChildrenGet function.
// note that we are skipping several of the typical elements of a page template // to focus on the children element // please see the 'creating a basic template' for other items you typically see in a template // including menu bars, etc. // always start your templates with any functions you require // to gather the data you need for the page // lets start by getting our child data $children = eV::pageChildrenGet($pageId,"title,summaryImage,summary,link"); // our opening html tags echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\" dir=\"ltr\"> "; // now for the head // notice we use some core variables here to specify the title, meta keywords and description // the contents of these variables are controlled by page management // note the use of the php htmlspecialchars function to ensure no characters in the variable content 'break' the tags echo " <head> <meta name=\"keywords\" content=\"" . htmlspecialchars($metaKeywords) . "\"> <meta name=\"description\" content=\"" . htmlspecialchars($metaDescription) . "\"> <title>" . htmlspecialchars($metaTitle) . "</title> </head> "; // start the body tag echo "<body>"; // lets build an outer table to hold our page content echo "<table width=779>"; // this is the top banner echo "<tr><td align=center><font size=6><b>WELCOME TO OUR WEB SITE</b></font></td></tr>"; // now lets display the center page content echo "<tr><td valign=top>"; // first im going to display the message output // this is a variable used to pass messages (errors, notifications, etc) from page to page for visitors // you want this highlighted so it is brought to their attention // only display this if it has value if(!empty($attributes['message'])) echo "<font color=red>" . $attributes['message']] . "</font><br><br>"; // center page content // pulled from core variables // the contents of these variables is controlled via page management echo "<b>$title</b><br><i>$subTitle</i><br><br>$copy<hr>"; // now I am going to show the children below the copy // note you can display the children any way you wish (listed, like articles, checkerboard, with/without images, etc) // just make sure you call on the fields you require via the fieldList attribute in the pageGetChildren function // I'm going to display a checkerboard list of children echo "<table align=center border=2><tr>"; // setting a counter // this is to keep track of each cell, so we know when to start the next row $counter = 0; // lets loop thru the children // remember $children is what we assigned the results of the pageGetChildren function foreach($children as $child) { // if we are after the 3rd cell, lets start a new row if($counter/3 == intval($counter/3) && $counter != 0) echo "</tr><tr>"; // increment the counter $counter++ // output the cell echo "<td valign=top width=200>"; echo "<a href=\"" . $child['link'] . "\"><img src=\"" . $child['summaryImage'] . "\" border=0></a>"; echo "<br><a href=\"" . $child['link'] . "\"><b>" . $child['title'] . "</b></a><br>" . $child['summary']; echo "</td>"; }; // close out the child table echo "</tr></table>"; // now lets close out the center content cell echo "</td></tr>"; // time for the bottom menu echo "<tr><td colspan=2 align=center> | "; foreach($bottomMenu as $menuItem) echo " <a href=\"" . $menuItem['link'] . "\" target=\"" . $menuItem['target'] . "\">" . $menuItem['text'] . "</a> | "; echo "</td></tr>"; // close out the outer wrapping table echo "</table>"; // close out the body and html echo "</body> </html>";
- For details on using children, and more examples, see the pageChildrenGet function.
- To many children to display on one page gracefully? use the handy pagination function to allow visitors to 'page' through a large number of results.