Dynamic news..

Discussion in 'Programming' started by kojakfilth, Jun 20, 2006.

  1. #1
    How to put dynamic news to my page? So i will always have fresh contents on my site.. I got an rss but its an java script. Search engine just ignores it.
     
    kojakfilth, Jun 20, 2006 IP
  2. DXL

    DXL Peon

    Messages:
    380
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #2
    There are plenty of (free) RSS scripts available for PHP, and probably also for any other language you may be using. Google is your friend :).
    By the way, if you don't have a lot of fresh content, there is no big need for search engines to check if there is something new at your site, because their current cached version is probably still accurate.
     
    DXL, Jun 20, 2006 IP
  3. shaileshk

    shaileshk Well-Known Member

    Messages:
    455
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #3
    :)
    News Format :filen name :newsformat.asp

    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <form name="form1" method="post" action="getnewsxml.asp">
    <table width="90%" border="0" cellpadding="5" cellspacing="">
      <tr>
        <td width="18%">&nbsp;</td>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td>Select Category </td>
        <td colspan="2"><select name="cmbcat" id="cmbcat">
          <option>Select</option>
          <option value="http://www.groupstalk.com/rss.php">groupstalk</option>
          <option value="http://www.citinews.in/rss.asp?catid=231">Europe</option>
    	   <option value="http://www.citinews.in/rss.asp?catid=232">Americas</option>
    	   <option value="http://www.citinews.in/rss.asp?catid=233">National  </option>
    	   <option value="http://www.citinews.in/rss.asp?catid=233">Entertainment  </option>
    	   <option value="http://www.citinews.in/rss.asp?catid=233">Education  </option>
        </select>    </td>
      </tr>
      <tr>
        <td>No of News </td>
        <td colspan="2"><select name="cmptot" id="cmptot">
          <option value="0">select</option>
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          <option value="4">4</option>
          <option value="5">5</option>
          <option value="6">6</option>
          <option value="7">7</option>
          <option value="8">8</option>
          <option value="9">9</option>
          <option value="10">10</option>
            </select></td>
      </tr>
      <tr>
        <td>Long Description </td>
        <td colspan="2"><select name="newstype" id="newstype">
          <option value="1">yes</option>
          <option value="0">no</option>
            </select></td>
      </tr>
      <tr>
        <td>Table border </td>
        <td colspan="2"><input name="tblborder" type="text" id="tblborder"></td>
      </tr>
      <tr>
        <td>Table width </td>
        <td width="18%"><input name="tblwidth" type="text" id="tblwidth"></td>
        <td width="64%"><select name="tblwidthtype" id="tblwidthtype">
          <option value="%">%</option>
          <option>Px</option>
                </select></td>
      </tr>
      <tr>
        <td>Table bgcolor </td>
        <td colspan="2"><input name="tblbgcolor" type="text" id="tblbgcolor"></td>
      </tr>
      <tr>
        <td>Border color </td>
        <td colspan="2"><input name="brdcolor" type="text" id="brdcolor"></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td>cell padding</td>
        <td colspan="2"><input name="tblpadding" type="text" id="tblpadding"></td>
      </tr>
      <tr>
        <td>cell spacing</td>
        <td colspan="2"><input name="tblspacing" type="text" id="tblspacing"></td>
      </tr>
      <tr>
        <td>Align </td>
        <td colspan="2"><select name="tblalign" id="tblalign">
          <option>select</option>
          <option value="left">Left</option>
          <option value="center">center</option>
                    </select></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2">
          <input type="submit" name="Submit" value="Submit">    </td>
      </tr>
    </table>
    </form>
    </body>
    </html>
    
    Code (markup):
    News Read file : rssnews.asp
    
    <%
    
    url=Request.Form("cmbcat")
    nonews=Request.Form("cmptot")
    tblborder=Request.Form("tblborder")
    tblwidth=Request.Form("tblwidth")
    tblwidthtype=Request.Form("tblwidthtype")
    tblbgcolor=Request.Form("tblbgcolor")
    brdcolor=Request.Form("brdcolor")
    tblpadding=Request.Form("tblpadding")
    
    tblspacing=Request.Form("tblspacing")
    tblalign=Request.Form("tblalign")
    newstype=Request.Form("newstype")
    Response.Write("<BR>")
    Response.Write(getNews(url,nonews,newstype,tblborder,tblwidth,tblwidthtype,tblbgcolor,brdcolor,tblspacing,tblpadding,tblAlign))
    
    Response.Write("getNews(")
    Response.Write(url&","&nonews&","&newstype&","&tblborder&","&tblwidth&","&tblwidthtype&","&tblbgcolor&","&brdcolor&","&tblspacing&","&tblpadding&","&tblAlign&")")
    
    
    
    function getNews(url,nonews,newstype,tblborder,tblwidth,tblwidthtype,tblbgcolor,brdcolor,tblspaceing,tblpadding,tblAlign)
    
    Response.Expires = -1
    
    URLToRSS = url
    
    
    MaxNumberOfItems = nonews
    
    
    MainTemplateHeader = "<table "
    
    if tblborder<>"" then
    MainTemplateHeader=MainTemplateHeader&" border="&tblborder
    end if
    if tblwidth<>"" then
    MainTemplateHeader=MainTemplateHeader&" width="&tblwidth&""&tblwidthtype&""
    end if
    if tblbgcolor<>"" then
    MainTemplateHeader=MainTemplateHeader&" bgcolor="&tblbgcolor
    end if
    if brdcolor<>"" then
    MainTemplateHeader=MainTemplateHeader&" bordercolor="&brdcolor
    end if
    if tblpadding<>"" then
    MainTemplateHeader=MainTemplateHeader&" cellpadding="&tblpadding
    end if
    
    if tblspacing<>"" then
    MainTemplateHeader=MainTemplateHeader&" cellspacing="&tblspacing
    end if
    if tblalign<>"" then
    MainTemplateHeader=MainTemplateHeader&" align="&tblalign
    end if
    
    
    
    
    MainTemplateHeader=MainTemplateHeader&">"
    
    MainTemplateFooter = "</table>"
    
    'temTemplate1 = "<tr><td><a href=" & """{LINK}""" & " target=" & chr(34) & "_blank" & chr(34) & ">{TITLE}</a><BR>{DESCRIPTION}</td></tr>"
    
    temTemplate1 = "<tr><td>"
    temTemplate2="</td></tr>"
    
    
    
    
    ErrorMessage = "Error has occured while trying to process " &URLToRSS & "<BR>Please contact web-master"
    
    Set xmlHttp = Server.CreateObject("MSXML2.XMLHTTP.3.0")
    xmlHttp.Open "Get", URLToRSS, false
    xmlHttp.Send()
    RSSXML = xmlHttp.ResponseText
    
    Set xmlDOM = Server.CreateObject("MSXML2.DomDocument.3.0")
    xmlDOM.async = false
    xmlDOM.LoadXml(RSSXML)
    
    Set xmlHttp = Nothing ' clear HTTP object
    
    Set RSSItems = xmlDOM.getElementsByTagName("item") ' collect all "items" from downloaded RSS
    Set RSStitle = xmlDOM.getElementsByTagName("title")
    
    rssTitle=RSStitle.item(0).text
    MainTableHeader="<th>"&rssTitle&"</th>"
    
    Set xmlDOM = Nothing ' clear XML
    
    RSSItemsCount = RSSItems.Length-1
    
    
    if RSSItemsCount > 0 then 
    Response.Write MainTemplateHeader
    Response.Write MainTableHeader
    End If
    
    j = -1
    
    For i = 0 To RSSItemsCount
    Set RSSItem = RSSItems.Item(i)
    
    for each child in RSSItem.childNodes
    Select case lcase(child.nodeName)
    case "title"
    RSStitle = child.text
    case "link"
    RSSlink = child.text
    case "description"
    RSSdescription = child.text
    End Select
    next
    If (InStr(RSSTitle,Keyword1)>0) or (InStr(RSSTitle,Keyword2)>0) or (InStr(RSSDescription,Keyword1)>0) or (InStr(RSSDescription,Keyword2)>0) then
    j = J+1
    if J< cint(nonews) then 
    Response.Write(temTemplate1)
    Response.Write("<b><a href="&RSSlink&">")
    Response.Write(RSStitle)
    Response.Write("</a></b>")
    if newstype="1" then
    Response.Write(RSSDescription)
    end if
    Response.Write(temTemplate2)
    
    End if
    End If 
    
    Next
    
    if RSSItemsCount > 0 then 
    Response.Write MainTemplateFooter
    else 
    Response.Write ErrorMessage
    End If
    end function
    %>
    
    Code (markup):
     
    shaileshk, Jun 22, 2006 IP
  4. Allan

    Allan Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Get a script that read rss feed and display it on your site, depending on what system you use, it could be just a matter of downloading a module or coding it yourself. You are right that javascript is not the way to go. On my system I use Drupal and I have to install a cron job on the server so it updates every day, otherwise I have to load a page to get it to update the news article.
     
    Allan, Jun 25, 2006 IP