Jshop custom sql within a template

It’s been along while since I posted anything tech related.. mainly down to it being low down my pecking order of interests right now though its still good fun. Like today I wanted to do my own thing within a jshop template… add my own template variables from a custom sql query. What I wanted to do was add a hidden section and then add sections within there to hold some banner images thus allowing content management by the client and the section wouldn’t be included in the main loop. Here’s how…

Add some custom php in the top of your template…


<?php
global $dbA;
$result = $dbA->retrieveAllRecordsFromQuery("select * from jss_sections WHERE parent = 23");
$this->theVariables["sectionRotate"] = $result;
?>

Line 2 is where you do your custom query to pull what ever you fancy from the database

Line 3 include the returned array into a custom variable.

Do a loop through your custom variable and output however you wish!


<#loop:sectionRotate#>
<div class="button">
<img src="{sectionRotate.thumbnail}" />
</div>
<#/loop#>

If you want to see the whole array to see what your working with obviously you can use;


<?php
print_r({*sectionRotate});
?>

Post by: Richard

Tags: , , ,

Leave a Reply