Welcome to Geeklog, Anonymous Tuesday, November 26 2024 @ 01:38 am EST

Geeklog Forums

where to put custom php code on the site


Status: offline

garfy

Forum User
Full Member
Registered: 01/02/05
Posts: 437
Location:EU
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 <?

 Quote

Status: offline

mst3kroqs

Forum User
Regular Poster
Registered: 10/18/05
Posts: 78
Location:Cary, NC USA
Quote 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 <?


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:

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
 Quote

Status: offline

garfy

Forum User
Full Member
Registered: 01/02/05
Posts: 437
Location:EU
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?
 Quote

Status: offline

mst3kroqs

Forum User
Regular Poster
Registered: 10/18/05
Posts: 78
Location:Cary, NC USA
Quote 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?

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
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
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

::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

Status: offline

garfy

Forum User
Full Member
Registered: 01/02/05
Posts: 437
Location:EU
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
 Quote

Status: offline

garfy

Forum User
Full Member
Registered: 01/02/05
Posts: 437
Location:EU
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
 Quote

Status: offline

garfy

Forum User
Full Member
Registered: 01/02/05
Posts: 437
Location:EU
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??
 Quote

Status: offline

jmucchiello

Forum User
Full Member
Registered: 08/29/05
Posts: 985
Quote 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

Change "echo" to "return".
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
Garfy

Read more here for php in static page :rtfm:

::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

Status: offline

garfy

Forum User
Full Member
Registered: 01/02/05
Posts: 437
Location:EU
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

 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
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
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

Status: offline

garfy

Forum User
Full Member
Registered: 01/02/05
Posts: 437
Location:EU
Quote by: cordiste

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



no no, it is stripped out from template
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
Garfy,

On my test site running Geeklog 1.5.0 with professionnal theme it does work Big Grin

::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

Status: offline

jmucchiello

Forum User
Full Member
Registered: 08/29/05
Posts: 985
Quote by: cordiste

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...)

That only works in header.thtml unless you are running CTL.
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
Yes Joe.

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
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
Hi Garfy,

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

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.

::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

Status: offline

::Ben

Forum User
Full Member
Registered: 01/14/05
Posts: 1569
Location:la rochelle, France
Sorry block was not visible. It is now Smile

::Ben
I'm available to customise your themes or plugins for your Geeklog CMS
 Quote

All times are EST. The time is now 01:38 am.

  • 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