Prev和Next with array

时间:2014-03-29 11:39:55

标签: javascript php jquery twitter

我使用foreach循环创建脚本,它提供所有项目,任何人都知道如何在页面上显示一个项目以及当有人点击下一个箭头显示下一个推文或点击上一个显示上一条推文时?

这是代码:

<?php include "tw/twitteroauth.php"; ?>
<?php
    $consumer = "";
    $consumersecret = "";
    $accesstoken = "";
    $accesstokensecret = "";

    $twitter = new TwitterOAuth($consumer, $consumersecret,$accesstoken, $accesstokensecret);

    ?>
<html>
<head>

<title>Tw</title>
      <meta charset="utf-8" />

</head>
<body>

<?php

$tweets = $twitter -> get('https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=MiDizajn&count=100');
foreach($tweets as $tweet){

       print_r($tweet -> text.'<br /><br />');

}


?>

</body>
</html>

结果如下:

Donec mauris leo, ultricies at nulla euismod, facilisis dapibus quam. Maecenas pharetra eros non dolor bibendum http://t.co/dZuDAW37pT...

proba neka

Win a brand new HTPC worth over 1400 Euro http://t.co/b70wypaQbo

I just joined @SteelSeries Christmas Illuminated contest to win a Dota 2 Mouse Bundle. You can too: http://t.co/NJxOJk6fyX

Ive just entered to win an Asus R9 280X Matrix Platinum thanks to OC3D! http://t.co/azbdOFmWIF

I just got a code for free Gems in the Settlers Online: @CastleEmpire http://t.co/JKLdoMQlU9

#darkside40

RT @d3expert: Follow us + retweet for a chance to win 1x Book of Cain and 1x Diablo 2013 Wall Calendar EU only. More giveaways: http://t ...

@palicomp are giving away an @amdradeon 7950HD Graphics Card!! Answer a question on facebook to enter! http://t.co/Yzhia6W1 #palicomp #amd

@goran_jovanovic http://t.co/iO1VZu6R

Win a PNY GeForce GTX 650Ti http://t.co/gft1TKWM

Winpics [20] http://t.co/z7uQaBrG via @ftw_nl

Corsair Vengeance Gaming Bundle Giveaway: http://t.co/y0Aqr74D

just requested a beta invite @koding, a new way for developers to work! http://t.co/n5cQZmpr

RT @POPodcast: Retweet for a chance to win Kingdom Rush HD from @ArmorGames! Mike is addicted and feeling generous! You have one hour to ...

@1v4nB Hvala!!!

@rain_wind_storm pogledaj nase radove od ranije na http://t.co/ezwp5LiS

@goran_jovanovic http://t.co/ggMUkCfd

@goran_jovanovic http://t.co/no8lrtae

Enter to win a #GIGABYTE G1.Assassin2 motherboard w/ @futurelooks @MEGATechNews @eSportsCN ! http://t.co/iZ5pyZYn

Follow @massluminosity on Twitter for the best #gamer #giveaways

http://t.co/kNLLbGWX

BARinfo - Šobić, Sklonište, Dado, Hanka, Laboratorija... u Baru http://t.co/gNG0B0d5

RT @D_eSports: Who wants to win a @ZOWIEGEAR MiCO? Retweet this message and follow @D_eSports and @ZOWIEGEAR to enter the competition! # ...

http://t.co/RACqraCP

RT @IvanSimoSimic: @goran_jovanovic Evo rjeshenja! http://t.co/O7U4WX0V

Ivy Bridge proven to suffer from poor thermal grease by http://t.co/aZgRZZds http://t.co/kYIBQ6r8 via @VRZone

http://t.co/73Agsa9N

RT @goran_jovanovic: http://t.co/Xl5KdprA

RT @BARinfo_me: NOVO!!!!! http://t.co/5PuGxJss http://t.co/FObQHl7e

Blic Online | EU neće ratifikovati sporazum Akta http://t.co/mUeZKQxV via @Blic_online

RT @BARinfo_me: Uskoro nešto novo...

RT @D3Sanc: We must fight harder! Don't let #D2 lose with 49% of the votes!!! http://t.co/EDKu0yqG

Help me win a #Diablo3 Beta Key! http://t.co/YOnHgpjD

I just entered to win a #Diablo3 Beta Key – follow @wowjuju and visit http://t.co/DtT0fD5h to enter the contest.

RT @d3expert: Round 5 of 5 of the Giveaway! Follow us + Retweet and have a chance of winning 5 Beta Keys.Winners, Rules and Details: htt ...

@Mare085Marko yummy :)

Hachitosh alive!!!

I just signed up for the Guild Wars 2 beta. Join the revolution! http://t.co/WVAQcqDE #GW2 #guildwars2 via @GuildWars2

RT @YourAnonNews: TANGO DOWN - Interpol main http://t.co/tmhiBKCj (via @blackTuesdayHG) #Anonymous #ActAgainstACTA

Intel 'Ivy Bridge' desktop chip prices leak - TechSpot News http://t.co/O3cg7f2i via @techspot

RT @YourAnonNews: I can't wait to someday tell my kids that their grandparents are older than the modern Internet. That won't blow their ...

RT @YourAnonNews: Love all. Trust few. Always paddle your own canoe. ツ

RT @YourAnonNews: ACTA is falling apart in Europe | GET INVOLVED and ACT AGAINST ACTA - Here's How: http://t.co/ImybhSoj

RT @YourAnonNews: #Anonymous. We are beyond common definitions. We are the movement, progression and realisation of an idea whose time h ...

RT @YourAnonNews: BREAKING: UK Seizes & Shuts Down Popular Music Blog RnBXclusive, Arrest Operators and Threaten Readers for Piracy | ht ...

RT @Blic_online: #svet Hakeri "Anonimusi" srušili sajt Interpola http://t.co/G9NmQ8Kz

ASrock Competition less than 30min left!!! http://t.co/zeChpmlW

New version of GPUz. http://t.co/ONbMqYCQ

Fresh from kitchen :) http://t.co/I0gmFdWw

Big changes to Diablo 3 detailed, more to come • News • http://t.co/6RsZneLV http://t.co/TiAElt7V

I support #wikipediablackout! Show your support here http://t.co/o2C0wUYb

14 Days Christmas Giveaway http://t.co/HR87Nuou

18 hours of overclocking

http://t.co/zTIkGWqc via @vijestime

http://t.co/sylX7wsV via @vijestime

Blic Online | Pogledajte kako su izgledale prve verzije "Gugla", Fejsbuka, Jutjuba... http://t.co/n6xWKl6G via @Blic_online

http://t.co/ezwtDls2

hmm

1 个答案:

答案 0 :(得分:0)

怎么样:

<body>
     <div id="tweets">
     <?php
        $tweets = $twitter -> get('https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=MiDizajn&count=100');
        $first = true;
        foreach($tweets as $tweet){
           print_r('<span'.($first?'':'style="display: none"').'>'.$tweet -> text.'</span><br /><br />');

           if($first){
              $first = false;
           }
        }
    ?>
   </div>

   <button id="prev">prev</button>
   <button id="next">next</button>
</body>

和jQuery:

$(document).ready(function(){
        $("#prev").click(function(){
            if( $("#tweets>span:visible").prev().size() > 0){
                $("#tweets>span:visible").hide().prev().show();
            }
        });

        $("#next").click(function(){
            if( $("#tweets>span:visible").next().size() > 0){
                $("#tweets>span:visible").hide().next().show();
            }
        });
});

我没有测试PHP部分,通常不使用PHP,但我认为这应该工作。当然你可以使用fadeOut和fadeIn代替隐藏和显示或做一些高级的淡化效果。