WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Running PHP code.. (18 posts)

  1. piperis
    Member
    Posted 6 years ago #

    I am trying to get a page to display an rss feed,
    i think i have found a php code that will do this,
    but i need help getting wordpress to run the code...

    i found a plugin but it doesnt support version 2.6
    can anyone help?

  2. jrm213
    Member
    Posted 6 years ago #

    It depends on where you want the rss feed to display.

    for example if you wanted it to display in the sidebar, you would open sidebar.php and place the code to display the feed in that file in the location you want it to appear. Can you give a little more detail?

  3. piperis
    Member
    Posted 6 years ago #

    i want to display the feed on a page...
    I have a page created, named News,
    and I want a news feed to appear under that page.

    Like i said i have tried several things but havent been able to get it working.

  4. jrm213
    Member
    Posted 6 years ago #

    ok, so we are talking about a page not a post.

    Edit page.php in your themes, theme directory ie(wp-content/themes/your-theme/page.php

    find where you want the rss feed to display, for example under your content.

    <div class="entry">
    <?php the_content('Read the rest of this entry &raquo;'); ?>
    </div>

    under that make a new div for your rss feed

    <?php
    if(is_page('news'))
    {
    ?>
    <div class="rss">;
    <?php
    //paste your rss feed display php code here
    ?>
    </div>;
    <?php
    }
    ?>
  5. jrm213
    Member
    Posted 6 years ago #

    I Don't know why it keeps putting ; next to the div and close div tags but those shouldn't be there.

  6. piperis
    Member
    Posted 6 years ago #

    thanks for ur reply....
    im trying to use this method:
    http://www.tonyrocks.com/index.php/tutorials/adding-an-ebay-rss-feed-to-your-wordpress-blog/

    but i cant get it to work, the lastrss file isnt helping.

    I just need a nice clean bit of code that will parse the rss

  7. piperis
    Member
    Posted 6 years ago #

    the best i can do is get it to say rss file not found...!

  8. piperis
    Member
    Posted 6 years ago #

    this is my code atm:

    <?php
    if(is_page('News'))
    {
    ?>
    <div class="rss">
    <?php
    // include lastRSS library
    include './lastRSS.php';

    // create lastRSS object
    $rss = new lastRSS;

    // setup transparent cache
    $rss->cache_dir = './cache';
    $rss->cache_time = 3600; // one hour

    // load some RSS file
    if ($rs = $rss->get('feed://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml')) {
    // here we can work with RSS fields
    }
    else {
    die ('Error: RSS file not found...');
    }
    ?>
    </div>
    <?php
    }
    ?>

  9. jrm213
    Member
    Posted 6 years ago #

    ok, well I am not positive on this, but feed:// really isn't valid. Some browsers may interpret or replace it for you if you paste that in the url.

    try http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml instead

  10. piperis
    Member
    Posted 6 years ago #

    changed it... nothing is being displayed, no errors or news... just blank page....

  11. jrm213
    Member
    Posted 6 years ago #

    ok, so now you have a variable called $rs which is an object that contains the result of the function call $rss->get . That object must have functions and variables associated with it to display the feed, check the provider of lastrss and see how they tell you to display your feed data. example:
    replace
    // here we can work with RSS fields

    with the following from one of t

    echo "<ul>\n";
        foreach($rs['items'] as $item) {
            echo "\t<li><a href=\"$item[link]\">".$item['title']."</a><br />".$item['description']."</li>\n";
            }
        echo "</ul>\n";

    change the above as needed to display your output styled the way you want it. Also, check out documentation on lastrss they have some good examples with sourcecode

  12. piperis
    Member
    Posted 6 years ago #

    just gave it a go, and it worked!!
    thanks sooo much, i have posted a few times to get this sorted and finally have sorted it, thanks to you!

    Top (wo)man!!!! lol
    Thanks again...

  13. piperis
    Member
    Posted 6 years ago #

    finally, how can i add some text just above the rss stuff?
    whats the code??

  14. jrm213
    Member
    Posted 6 years ago #

    You want some other text only on the News Page, but above the RSS Feed stuff?

    directly above:
    <div class="rss">

    put your content.

    example:

    <?php
    if(is_page('news'))
    {
    ?>
    <div>
    //put your text you want above the feed here
    </div>
    <div class="rss">
    <?php
    //paste your rss feed display php code here
    ?>
    </div>
    <?php
    }
    ?>
  15. piperis
    Member
    Posted 6 years ago #

    Thanks again!
    All sorted!

  16. Anonymous
    Unregistered
    Posted 6 years ago #

    So I'm having a similar problem... except I'm trying to retrieve my WordPress feed to display on my website. The feed is valid, but no matter what feed type I use (rss, rss2, atom, rdf), lastRSS won't retrieve it.

    This is how I call it:

    <?php include "./public/lastrss.php"; // include lastRSS
      $rss = new lastRSS; // Create lastRSS object
      $rss->cache_dir = './public/cache';
      $rss->cache_time = 43200;
      // Try to load and parse RSS file
      if ($rs = $rss->get("http://blog.worderella.com/index.php?feed=rss2")) {
        // Show last published articles (title, link, description)
        echo "<ul>\n";
        foreach($rs['items'] as $item) {
          echo "\t<li><a href=\"$item[link]\">".$item['title']."</a>".$item['pubDate']."</li>\n";
        }
        echo "</ul>\n";
      }
      else { echo "Items not found."; }
    ?>

    It returns "Items not found." on my website. Any suggestions?

  17. piperis
    Member
    Posted 6 years ago #

    Refering to:

    <?php include "./public/lastrss.php"; // include lastRSS
    $rss = new lastRSS; // Create lastRSS object
    $rss->cache_dir = './public/cache';

    make sure the files and cache folder are where you say they are.
    try putting them in other dir.

  18. adamiis111
    Member
    Posted 5 years ago #

    Is there no way to do this from within the page editing section for the individual page? For instance, if I want to add the date using the template variable the_date()

    http://codex.wordpress.org/Template_Tags/the_date

    But I just want this on that one page, not all pages using the page.php template.

    I'll post if I find the solution in the meantime.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.