Archived topic
Special page template not displaying footer
1 reply · Started by Eli on May 14, 2021
I have a page that was grandfathered in from our previous theme that was custom built to pull in our customer list with links to their sites. I had just copied it over and it worked out ok. Though it seems that it is not pulling in the footer, just the footer bar. What needs to change in this code in order to get the footer working properly? I've tried copying code from the other templates but it isn't working. Not a coder clearly!
Thanks.
Php file copied below. Page here: https://www.generalcode.com/library/
`<?php
/*
Template Name: eCode Library
*/
$statesToNames = array(
'AL'=>'Alabama',
'AK'=>'Alaska',
'AZ'=>'Arizona',
'AR'=>'Arkansas',
'CA'=>'California',
'CANADA'=>'Canada',
'CO'=>'Colorado',
'CT'=>'Connecticut',
'DE'=>'Delaware',
'DC'=>'District of Columbia',
'FL'=>'Florida',
'GA'=>'Georgia',
'HI'=>'Hawaii',
'ID'=>'Idaho',
'IL'=>'Illinois',
'IN'=>'Indiana',
'IA'=>'Iowa',
'KS'=>'Kansas',
'KY'=>'Kentucky',
'LA'=>'Louisiana',
'ME'=>'Maine',
'MD'=>'Maryland',
'MA'=>'Massachusetts',
'MI'=>'Michigan',
'MN'=>'Minnesota',
'MS'=>'Mississippi',
'MO'=>'Missouri',
'MT'=>'Montana',
'NE'=>'Nebraska',
'NV'=>'Nevada',
'NH'=>'New Hampshire',
'NJ'=>'New Jersey',
'NM'=>'New Mexico',
'NY'=>'New York',
'NC'=>'North Carolina',
'ND'=>'North Dakota',
'OH'=>'Ohio',
'OK'=>'Oklahoma',
'OR'=>'Oregon',
'PA'=>'Pennsylvania',
'RI'=>'Rhode Island',
'SC'=>'South Carolina',
'SD'=>'South Dakota',
'TN'=>'Tennessee',
'TX'=>'Texas',
'UT'=>'Utah',
'VT'=>'Vermont',
'VA'=>'Virginia',
'WA'=>'Washington',
'WV'=>'West Virginia',
'WI'=>'Wisconsin',
'WY'=>'Wyoming',
);
function loadExtra() {
$rows = array_map('str_getcsv', file('/home/bitnami/apps/wordpress/htdocs/wp-content/themes/generatepress_child/extra-codes.csv.txt'));
$header = array_shift($rows);
$csv = array();
foreach($rows as $row) {
$csv[] = (object)array_combine($header, $row);
}
return $csv;
}
function compareCustomers($a, $b) {
global $statesToNames;
if($a == $b) {
return 0;
}
if($statesToNames[$a->state] != $statesToNames[$b->state]) {
return ($statesToNames[$a->state] < $statesToNames[$b->state]) ? -1 : 1;
}
if($a->municipality != $b->municipality) {
return ($a->municipality < $b->municipality) ? -1 : 1;
}
if($a->county != $b->county) {
return ($a->county < $b->county) ? -1 : 1;
}
if($a->custId != $b->custId) {
return ($a->custId < $b->custId) ? -1 : 1;
}
if(!isset($a->url)) {
if(!isset($b->url)) {
return 0;
}
return -1;
}
if(!isset($b->url)) {
return 1;
}
if($a->url !== $b->url) {
return ($a->url > $b->url) ? -1 : 1;
}
return 0;
}
//debugging function
function var_dump_pre($mixed = null, $title = null) {
echo '
echo '<h6>';
echo $title;
echo '</h6>';
echo '
'; var_dump($mixed); echo '
';
echo '
';
return null;
}
//get the codes from eCode, prefereably from the cache but if not load them immediately
//$next = "http://bees.ecode360.com/api/v1/customers/search/findByPublic";
function loadCodes($statesToNames) {
$codes = [];
//$next = "http://172.16.0.250:8080/api/v1/customers/search/findByPublic";
//$next = "http://172.16.0.250:8080/api-internal/customer";
$apiKey = '24499d98b5155aa06417449e0d10c9094ea8924c';
$apiSecret = '967add0413ac2d59b9f604976c7443c71c743f49';
$next = 'https://api.ecode360.com/v1/customer';
$ch = curl_init();
if($_GET['use_test']) {
//we can't get dns from cloudflare so use the amazon name for the api gateway
$next = "https://5wmaoj4g7b.execute-api.us-east-1.amazonaws.com/test/customer?auth=yes";
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$apiAuth = array("api-key: $apiKey", "api-secret: $apiSecret");
curl_setopt($ch, CURLOPT_HTTPHEADER, $apiAuth);
curl_setopt($ch, CURLOPT_URL, $next);
try {
$res = curl_exec($ch);
$codes_page = json_decode($res);
//clean up the format of the data to "old style"
$custs = null;
$custs = $codes_page->results;
foreach ( $custs as $cust ) {
$cust->custId = $cust->id;
$cust->municipality = $cust->shortName;
$cust->county = $cust->counties[0];
}
$extra = array();
$extra = loadExtra();
$customers = array_merge($custs,$extra);
usort($customers,"compareCustomers");
$prevCustId = "";
foreach ( $customers as $i => $code ) {
if($code->custId != $prevCustId) {
if(isset($statesToNames[$code->state]) && substr($code->custId,0,2) != 'XX' && substr($code->custId,2,1) < 7) {
$codes[] = $code;
}
$prevCustId = $code->custId;
}
}
if(curl_errno($ch)) {
$codes = 'error';
echo("Curl error" . curl_error($ch));
}
curl_close($ch);
} catch(Exception $e) {
$codes = 'error';
}
//if we are in test mode don't update the cached state
if(!$isTest) {
set_transient('ecode_codes', $codes, 5 * MINUTE_IN_SECONDS);
}
return $codes;
};
?><?php get_header(); ?>
<?php
if(have_posts() ) {
while(have_posts()) {
the_post();
?><?php
//if the cached state is old or we are instructed to always refresh (dev_refresh) or we are configured to use test data (use_test) then fetch the list again
if ($_GET["dev_refresh"] || $isTest || false === ($codes = get_transient('ecode_codes')) || $codes == null || sizeof($codes) == 0) {
$codes = loadCodes($statesToNames);
}
//mapping of state code to name
?>
<style>
@media screen and (min-width: 926px){
h2.stateTitle {
margin-top: 8px;
}
}
</style>
<?php if($codes === "error") {
?>The eCode360 Library listing is not currently available. Please check back shortly.<?php
} else {
?>
$lastState = '';
foreach ( $codes as $i => $code ) {
$state = $code->state;
if($state != $lastState) {
if($lastState != '') {
//end last loops list
?>
<?php
}
$lastState = $state;
?>
" class="stateAnchor" style="top: -95px">
<h2 class="stateTitle"><?=$statesToNames[$state]?> (return to top)</h2>
}
?>
if(!empty($code->mapUrl) && strpos($code->mapUrl, "zoninghub.com") !== false) {
?>
mapUrl?>" target="_blank" class="codeMapLink" title="Open MapLink zoning map in a new tab">
<?php
}
?>
url != null ? $code->url : "http://ecode360.com/" . $code->custId?>" target="_blank">
<?= preg_replace('/, ' . preg_quote($code->state, '/') . '\b/' , '', $code->name) ?>
<?php
if(!empty($code->counties) && !empty($code->counties[0])) {
?>
<?php
} elseif (!empty($code->county)) {
?>
<?php
}
?>
<?php
}
if($state != '') {
?>
<?php
}
?>
<?php
}
}
} else {
?>
<?php
}
?>
<?php get_footer(); ?>
<?php
fastcgi_finish_request();
if(mt_rand(0,100) === 0) {
loadCodes();
}
// vim: ai:ts=2:sw=2:et
?>