SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Change between 2 images

    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!!

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?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 === $id 1;

    ?>

    <a href="?id=<?php echo $next_id?>">
        <img src="<?php echo $images[$id]['src']; ?>" alt="<?php echo $images[$id]['alt']; ?>" />
    </a>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much its working!!

  4. #4
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  5. #5
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Post the code you have so far and we'll take a look.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  6. #6
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?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->items05); // 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 === $id 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; ?>

  7. #7
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    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?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  8. #8
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes its true!
    for new - new.png (http://www.thinkandwell.com/noam/noam_img/new.png)
    for view - view.png (http://www.thinkandwell.com/noam/noam_img/view.png)

    Thank your very much!!!!!

  9. #9
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    In which case, you're going to need to keep track of which links your visitors viewed.

    Something along the lines of...
    PHP Code:
    <?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->items05); // 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.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  10. #10
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!!

  11. #11
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?
    PHP 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->items010); // 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 === $id 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>

  12. #12
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still wating for your repaly...

    Thanks man you are the best!!!!

  13. #13
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb

    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:
    PHP 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->items010); // 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 === $id 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->items010); // 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; ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •