Welcome to Geeklog, Anonymous Tuesday, November 26 2024 @ 01:38 am EST
Geeklog Forums
where to put custom php code on the site
garfy
<?
$random_number = rand(1,4);
if($random_number == 1){
echo "http://www.mysite.com/geek.jpg";
}
?>
I could not do it anywhere, i tried in index.php and it is not used or my site is offline if I use <?
mst3kroqs
I need to put this code on my site
<?
$random_number = rand(1,4);
if($random_number == 1){
echo "http://www.mysite.com/geek.jpg";
}
?>
I could not do it anywhere, i tried in index.php and it is not used or my site is offline if I use <?
I guess it depends upon what you're trying to accomplish here.
Note that if you tried to place this in a template file - the traditional template class would strip the php code, however the Caching Template Library (CTL) permits the insertion of php code in templates for evaluation.
You should also use the full <?php -code- ?> notation - the notation above is deprecated.
It would be helpful to understand the complete context of the requirement here - eg. are you trying to randomly serve this image to someone? Note that this url would need to be embedded in a full HTML directive to retrieve the image from the server, eg. a full (CTL) template snippet might look like:
.. html
.. html
<?php
$random_number = rand(1,4);
if($random_number == 1){
echo '<img src="/geek.jpg" />';
}
?>
.. html
.. html
I should also mention - due to the way that the template caching/output works - this tag may not appear precisely where you expect - experimentation will be necessary.
Good luck!
-m
garfy
I put it in the footer file of my template, the code looks like this
<?php
$random_number = rand(1,4);
if($random_number == 1){
echo '<img src="/layout/professional/images/logo-top.gif" />';
}
?>
and the image does not show up, if I look at he souce the exact code is displayed
For example how can I show banner image to every forth person, is it possible?
mst3kroqs
Yes I just want to serve the images to random selected people. I tried to post it in module but it was stripped out, and on index.php also did not work.
I put it in the footer file of my template, the code looks like this
<?php
$random_number = rand(1,4);
if($random_number == 1){
echo '<img src="/layout/professional/images/logo-top.gif" />';
}
?>
and the image does not show up, if I look at he souce the exact code is displayed
For example how can I show banner image to every forth person, is it possible?
1. Find the right place to place the <img> tag to produce the image you want on every page load by modifying the applicable template. The template to modify varies based upon what version of GeekLog, what theme you're using, and where you want the image to appear. Don't forget to clear your browser cache when testing, and also the server-side template cache if you're using CTL.
2. Install CTL, you need that to evaluate PHP code in templates.
3. Now try modifying the template to surround the <img> tag with the php conditional.
-m
::Ben
Static pages allow php
See also PHP Block How-To
::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
garfy
function phpblock_custom{
$random_number = rand(1,4);
if($random_number == 1){
echo '<img src="/geek.jpg" />';
}
and I get the error in the site
it must be something wrong with the code
I tried to post it on a static page and it is not working, the whole code can be seen in the page code
I posted this on my static page
<?php
$random_number = rand(1,4);
if($random_number == 1){
echo '<img src="/layout/professional/images/logo-top.gif" />';
}
?> the whole code can be seen in the code view, but only the image should appear
garfy
I ve put this code this time
function phpblock_showpic () {
$random_number = rand(1,4);
if($random_number == 1){
echo '<img src="/layout/professional/images/logo-top.gif" />';
}
}
and then create new block select it as php block and put phpblock_showpic in the appropriate field
the block does not show up at all
garfy
here is the code
<img src="/layout/peaceful/images/logo-top.gif" /> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
any help?? i put it in the block on the right side so it should not be at the top??
jmucchiello
I tried again
I ve put this code this time
function phpblock_showpic () {
$random_number = rand(1,4);
if($random_number == 1){
echo '<img src="/layout/professional/images/logo-top.gif" />';
}
}
and then create new block select it as php block and put phpblock_showpic in the appropriate field
the block does not show up at all
::Ben
Read more here for php in static page :rtfm:
::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
garfy
But as soon as I put some random text in the php block I get error, is it possible to put some random text in the php block??
static page works just fine but the problem is it does not show on every page like when you open the article it is not there, also when browsing forum it is not there
::Ben
You need to edit your theme if you want your "block" on every pages.
For exemple you can add this code where you need it (header.html, footer.html, leftblocks.html, rightblocks.html...)
<div>
<?php
$random_number = rand(1,4);
if($random_number == 1){
echo '<img src="/layout/professional/images/logo-top.gif" />';
}
?>
</div>
::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
garfy
Garfy,
You need to edit your theme if you want your "block" on every pages.
For exemple you can add this code where you need it (header.html, footer.html, leftblocks.html, rightblocks.html...)
<div>
<?php
$random_number = rand(1,4);
if($random_number == 1){
echo '<img src="/layout/professional/images/logo-top.gif" />';
}
?>
</div>
::Ben
no no, it is stripped out from template
jmucchiello
Garfy,
You need to edit your theme if you want your "block" on every pages.
For exemple you can add this code where you need it (header.html, footer.html, leftblocks.html, rightblocks.html...)
::Ben
Garfy if CTL is running you can reed more about Ability to place logic into the templates
::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
::Ben
I'm using your idea with videos on a opensimulator.fr. See the first center block witch is a static page and click on the thumbnail to see the video.
The code is in a static page allowing php
$random_number = rand(1,4);
echo '
<script type="text/javascript" src="js/flashembed.min.js"></script>
<script>
window.onload = function() {
flashembed("player",
{
src:\'FlowPlayerDark.swf\',
width: 320,
height: 190
},
{config: {
autoPlay:false,
controlBarBackgroundColor:\'0x2e8860\',
initialScale: \'scale\',
hideControls:true,
videoFile:\'http://opensimulator.fr/videos/video' . $random_number . '.flv\',
splashImageFile:\'videos/image' . $random_number . '.jpg\'
}}
);
}
</script>
<div style="width:100%; background:#000000; position:relative"><div style="position: absolute; width: 80px; top: 1em; right: 1em; color: #FFFFFF"> >> Play Video</div>
<div id="player" align="center"><img src="videos/image' . $random_number . '.jpg" /></div></div>
';
The flash player is flowplayer.
::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content