How to make scrolling news like Top Tweets on Twitter homepage? (PHP)

I want the site to use wp, and I want to add scroll news, such as Top Tweets, on the Twitter homepage. when a custom post receives a response in every part of my page, new topics will appear in this news feed. they all come from the last 10 items in the database. How to do it? Thanks

+3
source share
1 answer

With jQuery, you can make a Div slide and take it out of sight. http://docs.jquery.com/UI/Effects/Slide#overview .

div , . div 0,1,2 3-9 . javascript:

echo <<<CONTENT
<html>
<head>
       <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
       <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js">       
       </script>
       <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> 
       <script type="text/javascript">
        k=1;
        setInterval("livefeed(k++)",1000);
        function livefeed(i){
        slide(i);
        }

        function slide(i){
                 addTop((i+3)%10);
                removeBottom(i%10);
                 var j=((i-1)%10);
                 $('.livefeed').prepend($("#"+j));

        }

        function addTop(i){
                  var e=document.getElementById(i);
                  $("#"+i).fadeIn(1000);  
        }
        function removeBottom(i){
                  $("#"+i).fadeOut(1000);   
         }
</script>

</head>
<body>
CONTENT;

     echo "<div class='livefeed'>";
     for($i=9;$i>=0;$i--){
         if($i<4&&$i>0){
        echo "<div id='".$i."' >This is comment $i from the database</div>";
         }else{
        echo "<div style='display:none' id='".$i."'  >This is comment ".$i." from the database</div>";      
          }
     }
     echo "</div>";

, ... 7000 .

+4

Source: https://habr.com/ru/post/1787103/


All Articles