SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Limiting The Wordpress Posts

    Hi there,

    Okay, after a bit of redesign of my portfolio site, I've decided to include the latest blog posts. I found a thread via Google which provided the following link which pulls out the latest posts from the RSS Feed of my blog.

    Currently, the RSS Feed itself is pulling 10 out of the 15 posts currently in the blog database. However, I want to limit this to 3-5 so that it can be easily displayed on my site.

    Below is the link in question which is an exact copy of the code I currently have running.

    Parse an RSS Feed with ASP - Sample Source Code

    I expect there is some way to customise the RSS Feed itself or simply editing the existing ASP code provided on the page above....but I'm not sure how or where to edit it.

    If someone could help me out I'd be very grateful!

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,608
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code:
    For x = 0 to objItems.length - 1
    That's what is starting your loop over the feed. Assuming you're wanting maximum 3 results try replacing that line with these:
    Code:
    Dim iNum
    iNum = objItems.length - 1
    If iNum > 2 Then iNum = 2 '2 means 3 items, 0-based
    For x = 0 to iNum
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by siteguru View Post
    Code:
    For x = 0 to objItems.length - 1
    That's what is starting your loop over the feed. Assuming you're wanting maximum 3 results try replacing that line with these:
    Code:
    Dim iNum
    iNum = objItems.length - 1
    If iNum > 2 Then iNum = 2 '2 means 3 items, 0-based
    For x = 0 to iNum
    Hi there,

    Thanks very much for your advice. However, one niggling problem I currently have is that the unmodified code appears to be causing some errors when placed within my ASP page.

    However, when the line "<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>" is removed, the code works and the feeds are loaded as expected. Obviously this isn't ideal by any means.

    Unfortunately as I need to work on the remainder of the website, I am unable to provide a link. However, the error code I am receiving is:

    Code:
    Microsoft JScript compilation error '800a03f7'
    
    Unterminated string constant
    
    /fonttest/index.asp, line 127
    
    ' change the RSSURL variable to the exact URL of the RSS Feed you want to pull
    ------------------------------------------------------------------------------^
    Just to reiterate, this is the unmodified code which is straight from the original link posted - http://www.bustercollings.com/source...de-example.asp

  4. #4
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,608
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Erm. The code VBScript ASP but you've set the page to use JScript ASP. Make your mind up.
    Ian Anderson
    www.siteguru.co.uk

  5. #5
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi there,

    Sorry for such a late reply. Thank you so much for the code, it's now working perfectly - and also for your advice about doctypes (haha oops!).

    One last thing I want to do is format them so that the posts are in separate divs next to each other. Please could you tell me how I could separate the blog posts into different sections? (e.g. at the moment they are simply a list).

    If possible, I would also like to grab the date from the posts and display this alongside the other data already gathered.

    Thanks again for your help.

  6. #6
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,608
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Putting them in DIVs is simply a matter of structuring the HTML code around the <%=OutputHTML_1%> etc. parts (and adjusting HTML content of OutputHTML_1 etc.)

    As regards getting the dates, just add an extra Case statement for the "date" element, something like:
    Code:
    Case "date" 'Assuming the node element is actually called date
        thedate = objChild.text
    then using thedate variable in your HTML as appropriate.

    It's not difficult - you just need to get clear in your mind what the code is doing, and how you integrate that with HTML in a web page.
    Ian Anderson
    www.siteguru.co.uk

  7. #7
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    153
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great! Thanks very much for your help .

    By the way, if anyone's curious and checking out this post for their own blog, below is the code for pulling out the "pubDate" and also formatting it.

    Code:
    Case "pubdate"
                          pubDate = objChild.text
    
    ......
    
    ArrayTemp = split(pubDate, " ")
        pubDateFormat = ArrayTemp(0) & ArrayTemp(2) & " " & Cint(ArrayTemp(1))
        OutputHTML_3 = OutputHTML_3 & "<a href=""" & link & """>" & title & "</a>,&nbsp;Published:" & pubDateFormat & "<br />" & description & "<br />"
    Next
    Thanks again!


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
  •