Jump to content

Recommended Posts

Hi guys, not sure if this is possible or not cos im new to this but i was after some help in the right direction...

 

basicly what i wanna do is have a site with testimonials on each page... i don't want them to be the same on each and want them to change on reload randomly...

 

Eg - on index I have a testimonial from joe blogs - i go to about us and i have a testimonial from john doe - i go back to index and the testimonial has changed to king kong (ran out of anonymous names lol)

 

what would you suggest to make this possible... the testimonials are located in an include.

                 <?php

include 'testimonials.php';

?>

      <div class="main-subcontent">

        <div class="subcontent-unit-border-orange">
          <div class="round-border-topleft"></div><div class="round-border-topright"></div>
          <h1 class="orange">header</h1>
          <p>testimonial here</p>
        </div>

          
        <div class="subcontent-unit-border-green">
          <div class="round-border-topleft"></div><div class="round-border-topright"></div>
          <h1 class="green">content</h1>
          <p>content
</p>
        </div>
      </div>
    </div>

 

 

Link to comment
https://forums.phpfreaks.com/topic/200596-php-alternating-scripts/
Share on other sites

Exactly "HOW" are the testimonials stored in that file? I would suggest that in that include file you put the testimonials into an array and add a line to define a testimonial randomly.

 

testimonials.php

<?php

$testimonials = array(
    "It's Great! - Robert Thomas",
    "Never leave home without it - Bob Johnson",
    "It's a piece of Crap. Don't buy it!!! - Mr. Negativity."
);

$testimonial = $testimonials[array_rand($testimonials)];

?>

 

Then on the pages where you need a testimonial, include the file as you are now. Then in the content echo $testimonial where you need it:

<div class="main-subcontent">

        <div class="subcontent-unit-border-orange">
          <div class="round-border-topleft"></div><div class="round-border-topright"></div>
          <h1 class="orange">header</h1>
          <p><?php echo $testimonial; ?></p>
        </div>

          
        <div class="subcontent-unit-border-green">
          <div class="round-border-topleft"></div><div class="round-border-topright"></div>
          <h1 class="green">content</h1>
          <p>content</p>
        </div>
      </div>

it just gave me undefined variable errors... any ideas?

 

Well, it worked for me. I actually tested that code before I posted. Since you didn't take the time to post the actual error (with the line numbers) and the relevant code, there's nothing I can do to help.

Hey, thanks for your help, it was me being thick!!!

 

what i cant figure out tho is how to put an img and a href in to the script so that the testimonial shows an image and link... any ideas???

 

the code is below which im using for the testimonials:

<?php

$testimonials = array(
    "<h3>Mr Kibir Rahman T/A East India Trading Company</h3><P> 'Since opening our 5 restaurants you have really helped us.'<P>",
        
        
        
    "<h3>Steve Bird T/A 1 Stop Magic Carpets</h3><p>'I would like to thank your member of staff for helping me'<P> ",

);

$testimonial = $testimonials[array_rand($testimonials)];

?>

 

testimonials are fake of course... real ones are yet to be added lol, what im basicly after is on the first one an img with a link to the webite of the company and a link to more testimonials page, on the second just a link to more testimonials.

 

any ideas?

 

You can put whatever you want into the variables. Whatever you put in it will get used. If you know how to write the HTML code for an image, just include it into the testimonial string. The only thing to watch for is quotation marks. If you define a string with double quotation marks and you want to use double quotation marks in the string, you will need to escpe them (same goes for single quotation marks:

 

$testimonials = array(
    "<h3><a href=\"http://www.eastindia.com\">Mr Kibir Rahman T/A East India Trading Company</a></h3>
     <img src=\"http://www.eastindia.com\logo.gif\">
     <P>'Since opening our 5 restaurants you have really helped us.'<P>",

    "<h3>Steve Bird T/A 1 Stop Magic Carpets</h3><p>'I would like to thank your member of staff for helping me'<P> ",
);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.