Vote count:
0
I have made a function that take in the current page id and base on that result will ever show two .php file or just one .php file.
My question is: Have I approached this in the wright way?
<?php
function get_search_or_nav($page_id) {
if(isset($page_id)) {
$id = $page_id;
$pages = array('home', 'thank-you');
foreach($pages as $page){
if($page==$id)
$match = true;
}
if($match) {
include("dir/file_1.php");
include("dir/file_2.php");
}
elseif (!$match) {
include("dir/file_1.php");
}
}
}
?>
The $pages variable holds the $page_id array i.e.$pages = array('home', 'thank-you');
each .php file has a $page_id i.e index.php has $page_id = "home";
The array is a list of the matching $page_id's:
$pages = array('home', 'thank-you');
The call would then be:
get_search_or_nav($page_id);
Any help or advise would be great, this is my first question here so please excuse me if i have made any mistakes...
asked 15 secs ago
Created a php function to take in a page_id and based on the current page_id display or not display another php file
Aucun commentaire:
Enregistrer un commentaire