Posted on: 07/01/08 10:57am
By: garfy
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 <?
Re: where to put custom php code on the site
Posted on: 07/01/08 11:13am
By: mst3kroqs
Quote by: garfyI 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[*1] (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:
Text Formatted Code
.. 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
Re: where to put custom php code on the site
Posted on: 07/01/08 11:36am
By: garfy
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?
Re: where to put custom php code on the site
Posted on: 07/01/08 01:27pm
By: mst3kroqs
Quote by: garfyYes 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?
Suggest the following:
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
Re: where to put custom php code on the site
Posted on: 07/02/08 03:20am
By: ::Ben
Garfy ,
Static pages allow php
Warning: PHP code in your page will be evaluated if you enable this option. Use with caution !!
See also
PHP Block How-To[*2]
::Ben
Re: where to put custom php code on the site
Posted on: 07/02/08 11:13pm
By: garfy
I dont get this, I try to post in the lib custom at the end of the document
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
Re: where to put custom php code on the site
Posted on: 07/02/08 11:34pm
By: garfy
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
Re: where to put custom php code on the site
Posted on: 07/02/08 11:39pm
By: garfy
another update, the code seems to be working but the image is displayed at the top of the page, in fact in the code it is in the first line before head and body
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??
Re: where to put custom php code on the site
Posted on: 07/03/08 02:08am
By: jmucchiello
Quote by: garfyI 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
Change "echo" to "return".
Re: where to put custom php code on the site
Posted on: 07/03/08 02:54am
By: ::Ben
Re: where to put custom php code on the site
Posted on: 07/03/08 07:18am
By: garfy
Ok both methods work, the php block works fine and changing from echo to return did the trick, thanks
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
Re: where to put custom php code on the site
Posted on: 07/03/08 08:23am
By: ::Ben
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...)
Text Formatted Code
<div>
<?php
$random_number = rand(1,4);
if($random_number == 1){
echo '<img src="/layout/professional/images/logo-top.gif" />';
}
?>
</div>
::Ben
Re: where to put custom php code on the site
Posted on: 07/03/08 08:53am
By: garfy
Quote by: cordisteGarfy,
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...)
Text Formatted Code
<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
Re: where to put custom php code on the site
Posted on: 07/03/08 12:21pm
By: ::Ben
Garfy,
On my test site running Geeklog 1.5.0 with professionnal theme it does work
::Ben
Re: where to put custom php code on the site
Posted on: 07/03/08 01:10pm
By: jmucchiello
Quote by: cordisteGarfy,
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...)
That only works in header.thtml unless you are running CTL.
Re: where to put custom php code on the site
Posted on: 07/04/08 06:23am
By: ::Ben
Re: where to put custom php code on the site
Posted on: 07/07/08 07:36am
By: ::Ben
Hi Garfy,
I'm using your idea with videos on a
opensimulator.fr[*5] . 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
Text Formatted Code
$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[*6] .
::Ben
Re: where to put custom php code on the site
Posted on: 07/07/08 10:05am
By: ::Ben
Sorry block was not visible. It is now
::Ben