taly88
March 7, 2010, 12:50pm
1
Hello,
Im tray to do some script that change between 2 images:
I want to show one image that eich click chage it.
When i click on the image it change to img1 and when i click again it chage to img2.
Change btween img1 to img2 and img2 to img1…
How i can do it?
Only with PHP and HTML, i cant use JS
Thank you very much!!
taly88
March 7, 2010, 3:29pm
2
Thank you very much its working!!
<?php
$images = array(
1 => array(
'alt' => 'one',
'src' => 'one.jpg'
),
2 => array(
'alt' => 'two',
'src' => 'two.jpg'
)
);
$id = 1;
if(false === empty($_GET['id']) && true === in_array($_GET['id'], array(1,2))){
$id = (int)$_GET['id'];
}
$next_id = 1 === $id ? 2 : 1;
?>
<a href="?id=<?php echo $next_id; ?>">
<img src="<?php echo $images[$id]['src']; ?>" alt="<?php echo $images[$id]['alt']; ?>" />
</a>
taly88
March 7, 2010, 5:31pm
4
AnthonySterling, i need help again.
Itake your code its work great, but i have a loop, and i need show the img for eich item on loop, the problem is when i click on image it chage for the all item on loop, but i want its chage only for the image that i click…
I hope you can understand me…
What i can to do for onlt hte image that i click it, will chage?
If the code is in my loop…
Thanks
Post the code you have so far and we’ll take a look.
taly88
March 7, 2010, 6:41pm
6
<?php
include_once(ABSPATH.WPINC.'/rss.php'); // path to include script
$feed = fetch_rss('http://news.google.com/news?pz=1&cf=all&ned=us&hl=iw&q=%D7%AA%D7%A0%D7%95%D7%91%D7%94&cf=all&output=rss'); // specify feed url
$items = array_slice($feed->items, 0, 5); // specify first and last item
?>
<?php if (!empty($items)) : ?>
<ul>
<?php foreach ($items as $item) : ?>
<p>
<?php
$images = array(
1 => array(
'alt' => 'one',
'src' => 'http://www.thinkandwell.com/noam/noam_img/view.png'
),
2 => array(
'alt' => 'two',
'src' => 'http://www.thinkandwell.com/noam/noam_img/new.png'
)
);
$id = 2;
if(false === empty($_GET['id']) && true === in_array($_GET['id'], array(1,2))){
$id = (int)$_GET['id'];
}
$next_id = 1 === $id ? 2 : 1;
?>
<a href="?id=<?php echo $next_id; ?>">
<img src="<?php echo $images[$id]['src']; ?>" alt="<?php echo $images[$id]['alt']; ?>" /> <a href="<?php echo $item['link']; ?>"><?php echo $item['title']; ?></a>
</a>
<?php endforeach; ?>
<?php endif; ?>
Given the image names, I’m going to guess that you want to display the new image on unread news items, and the other image if the visitor has read said item?
In which case, you’re going to need to keep track of which links your visitors viewed.
Something along the lines of…
<?php
session_start();
if(false === array_key_exists('viewed', $_SESSION)){
$_SESSION['viewed'] = array();
}
if(false === empty($_GET['view'])){
array_push($_SESSION['viewed'], $_GET['view']);
header('Location: ' . base64_decode($_GET['view']));
exit;
}
include_once(ABSPATH.WPINC.'/rss.php'); // path to include script
$feed = fetch_rss('http://news.google.com/news?pz=1&cf=all&ned=us&hl=iw&q=%D7%AA%D7%A0%D7%95%D7%91%D7%94&cf=all&output=rss'); // specify feed url
$items = array_slice($feed->items, 0, 5); // specify first and last item
?>
<?php foreach($items as $item): ?>
<p>
<?php if(true === in_array(base64_encode($item['link']), $_SESSION['viewed'])): ?>
<img src="http://www.thinkandwell.com/noam/noam_img/new.png" />
<?php else: ?>
<img src="http://www.thinkandwell.com/noam/noam_img/view.png" />
<?php endif; ?>
<a href="?view=<?php echo base64_encode($item['link']); ?>">
<?php echo $item['title']; ?>
</a>
</p>
<?php endforeach; ?>
We create a proxy of sorts for any links the user wishes to see, when the user clicks the link, the script runs again and ‘registers’ this click then sends the visitor to the intended url.
We then use this data to figure out if the visitor has visited one of the links or not.
taly88
March 7, 2010, 7:03pm
9
taly88
March 7, 2010, 7:33pm
10
Thank you!!
When i tray to past your code i get trubbls… its because i post here only part of my source and you do big chage here.
So here is my full code, can you exmple your sulotion agin in this full code?
<!---רשימה רק כותרות --->
<h2>תקציר מהיר לנושאים עקריים בדיון</h2>
<?php
include_once(ABSPATH.WPINC.'/rss.php'); // path to include script
$feed = fetch_rss('http://news.google.com/news?pz=1&cf=all&ned=us&hl=iw&q=%D7%AA%D7%A0%D7%95%D7%91%D7%94&cf=all&output=rss'); // specify feed url
$items = array_slice($feed->items, 0, 10); // specify first and last item
?>
<?php if (!empty($items)) : ?>
<ul>
<?php foreach ($items as $item) : ?>
<p>
<?php
$images = array(
1 => array(
'alt' => 'one',
'src' => 'http://www.thinkandwell.com/noam/noam_img/view.png'
),
2 => array(
'alt' => 'two',
'src' => 'http://www.thinkandwell.com/noam/noam_img/new.png'
)
);
$id = 2;
if(false === empty($_GET['id']) && true === in_array($_GET['id'], array(1,2))){
$id = (int)$_GET['id'];
}
$next_id = 1 === $id ? 2 : 1;
?>
<a href="?id=<?php echo $next_id; ?>">
<img src="<?php echo $images[$id]['src']; ?>" alt="<?php echo $images[$id]['alt']; ?>" border="0px"/> <a href="<?php echo $item['link']; ?>"><?php echo $item['title']; ?></a>
</a>
<?php endforeach; ?>
<?php endif; ?>
<br>
<hr>
taly88
March 7, 2010, 7:24pm
11
Only if you can help me, i tray to build bar with 3 icons that change onclick.
The icon show in loop for eich new.
My icons:
icon NU 1:
new.png <–> view.png
icon NU 2:
no-imp.png <–> imp.png
icon NU 3:
none.png <–> work.png <–> no-full.png <–> ok.png
Thank’s man you are the ONE!!
taly88
March 9, 2010, 11:08am
12
Still wating for your repaly…
Thanks man you are the best!!!
taly88
March 9, 2010, 1:29pm
13
I have a problem with your script its not run in my site…
Also, the link of eich item is link to other site and not link in my site.
Can you help me please to bulid this script, i only need the icon show for eich item in my loop, but when i click on icon is change only the icon that i click him.
It good to me that i change the icon with click and without If I went into the actual link or not…
Thank you very much!!!
Here is my full code:
<!---רשימה רק כותרות --->
<h2>תקציר מהיר לנושאים עקריים בדיון</h2>
<?php
include_once(ABSPATH.WPINC.'/rss.php'); // path to include script
$feed = fetch_rss('http://news.google.com/news?pz=1&cf=all&ned=us&hl=iw&q=%D7%AA%D7%A0%D7%95%D7%91%D7%94&cf=all&output=rss'); // specify feed url
$items = array_slice($feed->items, 0, 10); // specify first and last item
?>
<?php if (!empty($items)) : ?>
<ul>
<?php foreach ($items as $item) : ?>
<p>
<?php
$images = array(
1 => array(
'alt' => 'one',
'src' => 'http://www.thinkandwell.com/noam/noam_img/view.png'
),
2 => array(
'alt' => 'two',
'src' => 'http://www.thinkandwell.com/noam/noam_img/new.png'
)
);
$id = 2;
if(false === empty($_GET['id']) && true === in_array($_GET['id'], array(1,2))){
$id = (int)$_GET['id'];
}
$next_id = 1 === $id ? 2 : 1;
?>
<a href="?id=<?php echo $next_id; ?>">
<img src="<?php echo $images[$id]['src']; ?>" alt="<?php echo $images[$id]['alt']; ?>" border="0px"/> <a href="<?php echo $item['link']; ?>"><?php echo $item['title']; ?></a>
</a>
<?php endforeach; ?>
<?php endif; ?>
<br>
<hr>
<br>
<h2>דיונים</h2>
<!---RSS מלא --->
<?php
include_once(ABSPATH.WPINC.'/rss.php'); // path to include script
$feed = fetch_rss('http://news.google.com/news?pz=1&cf=all&ned=us&hl=iw&q=%D7%AA%D7%A0%D7%95%D7%91%D7%94&cf=all&output=rss'); // specify feed url
$items = array_slice($feed->items, 0, 10); // specify first and last item
?>
<?php if (!empty($items)) : ?>
<?php foreach ($items as $item) : ?>
<h2><a href="<?php echo $item['link']; ?>"><?php echo $item['title']; ?></a></h2>
<p><?php echo $item['summary']; ?></p>
<?php endforeach; ?>
<?php endif; ?>