Toube
asked on
Changing templates using php.
Hi,
I've made 3 templates or more exactly 3 folders that have different pictures and css files in them.
And the index.php looks the following way:
<?php
$folder=$_REQUEST["folder" ];
?>
<head>
<title>Toubes Design</title>
<meta content="Web Design, Internetsivut, Kotisisvut" name="Toubes Design" />
<link rel="stylesheet" href="<?=$folder?>/toubesd esign.css" />
</head>
<body>
<div id="banner">
<img src="<?=$folder?>/banner_t est1.jpg"/ >
</div>
<p class="nav">
<a href="http://www.toubes-page.net/td"><img src="<?=$folder?>/etusivu_ o.jpg" name="etusivu" width="91" height="25" border="0"></a></p>
<p class="nav">
<a href="yritys" onMouseOut="MM_swapImgRest ore()" onMouseOver="MM_swapImage( 'yritys',' ','<?=$fol der?>/yrit ys_o.jpg', 1)"><img src="<?=$folder?>/yritys.j pg" name="yritys" width="72" height="25" border="0"></a></p>
<p class="nav">
<a href="palvelut" onMouseOut="MM_swapImgRest ore()" onMouseOver="MM_swapImage( 'palvelut' ,'','<?=$f older?>/pa lvelut_o.j pg',1)"><i mg src="<?=$folder?>/palvelut .jpg" name="palvelut" width="95" height="25" border="0"></a></p>
<p class="nav">
<a href="portfolio" onMouseOut="MM_swapImgRest ore()" onMouseOver="MM_swapImage( 'portfolio ','','<?=$ folder?>/p ortfolio_o .jpg',1)"> <img src="<?=$folder?>/portfoli o.jpg" name="portfolio" width="100" height="25" border="0"></a></p>
<p class="nav">
<a href="yhteystiedot" onMouseOut="MM_swapImgRest ore()" onMouseOver="MM_swapImage( 'yhteystie dot','','< ?=$folder? >/yhteysti edot_o.jpg ',1)"><img src="<?=$folder?>/yhteysti edot.jpg" name="yhteystiedot" width="120" height="25" border="0"></a></p>
<p class="nav"><img style="border: none; width: 422px; height: 25px;" src="<?=$folder?>/right.jp g" alt="left" /></p>
<br/><br/>
</div>
<div id="bg">
<div class="logo_bg">
<div></div>
<p class="navtop"></p>
<div class="left_box">
<div id="left_bar">
<span style="margin-left: 33px; font-size: 11px;">Ajankohtaista</span >
</div>
<div id="left_sisalto"><span style="color: #ffffff; font-weight: bold;">16.11.2006</span> - Toubes Design sivut saanut uuden ulkoasun, palautetta saa antaa.<p id="hr"></p>
<span style="color: #ffffff; font-weight: bold;">10.9.2006</span> - Metsämäki Tuotanto Oy:n sivut saatiin valmiiksi. <p id="hr"></p>
Lisää uutisia <span class="linkit"><a style="font-size: 11px;" href="index.php?id=content &page=uuti sia">t&aum l;äll ä.</a ></span>
</div>
</div>
<div class="middle_box">
<div id="middle_bar">
<?php
if (isset($_GET['page']) && isset($_GET['id']) && file_exists('pages/'.$_GET [id].'/'.$ _GET[page] .'.php'))
{
include 'pages/'.$_GET[id].'/'.$_G ET[page].' .php';
}
else
{
include 'pages/content/main.php';
}
?>
</div>
</div>
</div>
<div class="left_box_low">
<div id="left_bar">
<span style="margin-left: 33px; font-size: 11px;">2 Uusinta</span>
</div>
<div id="left_sisalto">
Kaksi viimeisimmät websivujen tuotannot ovat:
<ul class="linkit">
<li style="list-style-image: url(<?=$folder?>/point.jpg );"><a style="font-size: 11px;" href="http://www.metsamaki.fi" onclick="window.open('http://www.metsamaki.fi'); return false;">Metsämäk i Tuotanto Oy</a></li>
<div style="padding-top: 6px;"></div>
<li style="list-style-image: url(<?=$folder?>/point.jpg );"><a style="font-size: 11px;" href="http://www.sipoo.fi/kallback_barntradgard/" onclick="window.open('http://www.sipoo.fi/kallback_barntradgard/'); return false;">Kallbäck Barnträdgård</a></li>
</ul>
</div>
</div>
<div class="left_box_low">
<div id="left_bar">
<span style="margin-left: 33px; font-size: 11px;">Ota yhteyttä</span>
</div>
<div id="left_sisalto">
Jos haluat ottaa meihin yhteyttä, antaa palautetta tai jättää tarjouspyyntö voit tehdä sen yhteystiedot sivulta. <a href="index.php?folder=kes a">kesä</a > <a href="index.php?folder=tal vi">Talvi< /a> <a href="index.php?folder=syk sy">Syksy< /a>
<ul class="linkit">
<li style="list-style-image: url(<?=$folder?>/point.jpg );"><a href="http://www.toubes-page.net/td/yhteystiedot">Yhteystiedot sivulle</a></li></div>
</ul>
</div>
</div>
<div id="footer">
<div id="footer_text">Nallitie 8 D 24 | 00940 Helsinki | 050-4342840 | info@toubesdesign.com </div>
<img id="footer2" src="<?=$folder?>/footer2. jpg"/>
</body>
</html>
i got some good advices from the following page:
https://www.experts-exchange.com/questions/22066053/Php-change-template.html
So what I have done is that I have replaced all the images url with <?=$folder?> and changing the the templates with the following link: index.php?folder=kesa
But the problem that I'm having is that when a user browses to the main address of the page in this case http://www.toubes-page.net/td/test/ the css file is not activated and the whole page looks very messy.
So is there some way to get the main address to work?
Thanks in advance.
-Toby
I've made 3 templates or more exactly 3 folders that have different pictures and css files in them.
And the index.php looks the following way:
<?php
$folder=$_REQUEST["folder"
?>
<head>
<title>Toubes Design</title>
<meta content="Web Design, Internetsivut, Kotisisvut" name="Toubes Design" />
<link rel="stylesheet" href="<?=$folder?>/toubesd
</head>
<body>
<div id="banner">
<img src="<?=$folder?>/banner_t
</div>
<p class="nav">
<a href="http://www.toubes-page.net/td"><img src="<?=$folder?>/etusivu_
<p class="nav">
<a href="yritys" onMouseOut="MM_swapImgRest
<p class="nav">
<a href="palvelut" onMouseOut="MM_swapImgRest
<p class="nav">
<a href="portfolio" onMouseOut="MM_swapImgRest
<p class="nav">
<a href="yhteystiedot" onMouseOut="MM_swapImgRest
<p class="nav"><img style="border: none; width: 422px; height: 25px;" src="<?=$folder?>/right.jp
<br/><br/>
</div>
<div id="bg">
<div class="logo_bg">
<div></div>
<p class="navtop"></p>
<div class="left_box">
<div id="left_bar">
<span style="margin-left: 33px; font-size: 11px;">Ajankohtaista</span
</div>
<div id="left_sisalto"><span style="color: #ffffff; font-weight: bold;">16.11.2006</span> - Toubes Design sivut saanut uuden ulkoasun, palautetta saa antaa.<p id="hr"></p>
<span style="color: #ffffff; font-weight: bold;">10.9.2006</span> - Metsämäki Tuotanto Oy:n sivut saatiin valmiiksi. <p id="hr"></p>
Lisää uutisia <span class="linkit"><a style="font-size: 11px;" href="index.php?id=content
</div>
</div>
<div class="middle_box">
<div id="middle_bar">
<?php
if (isset($_GET['page']) && isset($_GET['id']) && file_exists('pages/'.$_GET
{
include 'pages/'.$_GET[id].'/'.$_G
}
else
{
include 'pages/content/main.php';
}
?>
</div>
</div>
</div>
<div class="left_box_low">
<div id="left_bar">
<span style="margin-left: 33px; font-size: 11px;">2 Uusinta</span>
</div>
<div id="left_sisalto">
Kaksi viimeisimmät websivujen tuotannot ovat:
<ul class="linkit">
<li style="list-style-image: url(<?=$folder?>/point.jpg
<div style="padding-top: 6px;"></div>
<li style="list-style-image: url(<?=$folder?>/point.jpg
</ul>
</div>
</div>
<div class="left_box_low">
<div id="left_bar">
<span style="margin-left: 33px; font-size: 11px;">Ota yhteyttä</span>
</div>
<div id="left_sisalto">
Jos haluat ottaa meihin yhteyttä, antaa palautetta tai jättää tarjouspyyntö voit tehdä sen yhteystiedot sivulta. <a href="index.php?folder=kes
<ul class="linkit">
<li style="list-style-image: url(<?=$folder?>/point.jpg
</ul>
</div>
</div>
<div id="footer">
<div id="footer_text">Nallitie 8 D 24 | 00940 Helsinki | 050-4342840 | info@toubesdesign.com </div>
<img id="footer2" src="<?=$folder?>/footer2.
</body>
</html>
i got some good advices from the following page:
https://www.experts-exchange.com/questions/22066053/Php-change-template.html
So what I have done is that I have replaced all the images url with <?=$folder?> and changing the the templates with the following link: index.php?folder=kesa
But the problem that I'm having is that when a user browses to the main address of the page in this case http://www.toubes-page.net/td/test/ the css file is not activated and the whole page looks very messy.
So is there some way to get the main address to work?
Thanks in advance.
-Toby
ASKER
Hi,
f ($_REQUEST["folder"] <> ""){
<link rel="stylesheet" href="<?=$_REQUEST["folder "]?>/style .css />
}else{
<link rel="stylesheet" href="syksy/style.css />
}
got this to test out.. but I can't get it to work, and I'm not sure where to place the could?
Thanks,
Toby
f ($_REQUEST["folder"] <> ""){
<link rel="stylesheet" href="<?=$_REQUEST["folder
}else{
<link rel="stylesheet" href="syksy/style.css />
}
got this to test out.. but I can't get it to work, and I'm not sure where to place the could?
Thanks,
Toby
You'd rather have:
$templates = array('syksy', 'template2','template3');
if(isset($_REQUEST['folder ']) && in_array($_REQUEST['folder ']) {
$folder = $_REQUEST['folder'];
} else {
$folder = 'syksy';
}
And then just use <link rel="stylesheet" href="<?php echo $folder;?>/style.css" />
-r-
$templates = array('syksy', 'template2','template3');
if(isset($_REQUEST['folder
$folder = $_REQUEST['folder'];
} else {
$folder = 'syksy';
}
And then just use <link rel="stylesheet" href="<?php echo $folder;?>/style.css" />
-r-
ASKER
ok, got the default working now, but when I try to change the style it gives me the follownig error:
Warning: Wrong parameter count for in_array() in /home/pt4517/public_html/t d/test/ind ex.php on line 6
Line 6: if(isset($_REQUEST['folder ']) && in_array($_REQUEST['folder ']))
-Toby
Warning: Wrong parameter count for in_array() in /home/pt4517/public_html/t
Line 6: if(isset($_REQUEST['folder
-Toby
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, it works.
Though now I have one more little thing, how do i get the template to stay selected when i change pages in the site.. so that it doesn't reverse back to the default template when a link is clicked?
when I go to the page http://www.toubes-page.net/td/test/index.php?id=content&page=uutisia and i have selected another template than the default one, but it still changes the template to default?
Thanks,
-Toby
Though now I have one more little thing, how do i get the template to stay selected when i change pages in the site.. so that it doesn't reverse back to the default template when a link is clicked?
when I go to the page http://www.toubes-page.net/td/test/index.php?id=content&page=uutisia and i have selected another template than the default one, but it still changes the template to default?
Thanks,
-Toby
-r-