Skip to content
WJunction - Webmaster Forum

How to make an Auto changing text with link via html??

Status
Not open for further replies.
How to make an Auto changing text with link via html??

I need to know what code i must use to make a TEXT with links changing by timer or even by page reload so each time the user move from page to page the text changes.

the text will be with links to another pages on same site or even to outside from it it looks like this:

free games ( as first text for exa )
hot offers ( as second text for exa)
... and so on

so the user will see more than one text while he reading or looking at my site

Thanks
 

9 comments

Example through PHP:
PHP:
<?php

$text = array(
'My first text',
'rotating',
'on each page reload',
'......',
'so on.');
 
$randomIndex = rand(0, count($text) - 1);
echo "$text[$randomIndex]";

?>
 
Thanks Bro for help

But what about link for each text?
what about timer option?
some details about this code what i can change or use inside it?

thanks so much
 
PHP:
<?php

$text = array(
'My first text' => 'http://mylink1/', 
'rotating' => 'http://mylink2/', 
'on each page reload' => 'http://mylink3/'
);

$random = array_rand($text); 
echo "<a href=\"$random\">$text[$random]</a>";

?>

That'll take care of your link for each text. There are endless possibilities, you could use a database instead of the pre-defined array.

As far as timer is concerned, check out jQuery based link rotators - I guess that's what you're looking for.
 
demo: http://jsfiddle.net/3p87Z/

PHP:
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
	<title>Change Text</title>
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
	<script type="text/javascript">
	$(document).ready(function() {
		// this shit done by mRAza
		// setting current element
		var current = 0;
		// starting interval for 2 seconds
		setInterval(changeText, 2000);
		
		function changeText(){
		// links array with text to tdisplay
		var links =  [      
							{"text" : "google site",  "link" : 'http://google.com' },
							{"text" : "yahoo web",  "link" : 'http://yahoo.com'},
							{"text" : "wjunction ftw",  "link" : 'http://wjunction.com'}
					]
				// lets check if total arrays are reached so we start from first element	
				if(links.length == current){
					current = 0;
				}
				// change the text
				setTimeout(function() {
					$("#demo").text(links[current]['text']).attr('href', links[current]['link']);
					current++;
				 }, 1900);
		}
	});
	</script>
  </head>
 <body>
	<div><a  id="demo" href="http://google.com">google</a></div>
 </body>
 
 </html>
 
Last edited:
yes but remember next time I might not help you if I dont see any code from your side, First always try to do it and when you cant do it yourself then post thread with your code....that's way you will learn....goodluck
 
i try to put this code with my wanted links on Joomla html modul but it does not work only show first text and not change by itself

anything i have to make?
thanks
 
Status
Not open for further replies.

About the author

M
Active Member · Joined
573
Messages
11
Reactions
18
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom