I have a PHP script that someone made me to pull in RSS feeds from another site and the only way I could think of getting it into my website and to look like all my other pages was to make a template for it. But the thing is I need to re-make this script about 40 times - there is about 40 different feeds I need and they all need to be on their own page. So I'm going to end up having HEAPS of different templates and that is a bit messy so I need to find another way to do it. This is the code that Kerosene (thanks again) helped me with and I basically need to do it over and over again except changing the RSS feed with a different location each time - it is for weather feeds. <?php function My_simplexml_load_file($URL) { $ch = curl_init($URL); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); $xml = simplexml_load_string(curl_exec($ch)); curl_close($ch); return $xml; } ?> <?php $url='http://www.weathermap.co.nz/feed/boating/kaikoura-peninsula'; $xml = My_simplexml_load_file($url); if ($xml!=''){ foreach ($xml->channel->item as $item){ $description = $item->description; echo $description; } } ?> Code (markup): I am by no means a Programmer and this is my first time playing with these sorts of scripts so I'm a bit lost and asking for help everyday.
Modify (add PHP code) your custom page template and save it with different name using a Text Editor. Then login to WordPress, create a new page and choose that custom page template. Hope this works!
Thanks for your help but I don't think I explained my situation properly, sorry. I have been doing it this way, but the list of templates has started to get massive and I wanted to know if there was another way I could do it. Still thanks for your input though.
Just to add to this, after going through and seeing how many RSS feeds I have, its 299 RSS feeds.............
Why wouldn't you just use one custom wordpress page template and set a custom field for something like feedurl and then pass custom field to the above function? add to your code : $feedurl = "WHATEVER_YOU_NAME_THE_CUSTOM_FIELD"; $url = get_post_meta($post_id, $feedurl, $single); if(!$url) { echo "<strong> Feed Unavailable </strong>"; } else { $xml = My_simplexml_load_file($url); if ($xml!=''){ foreach ($xml->channel->item as $item){ $description = $item->description; echo $description; } } } ?> This way, whatever the page/post title is could be used as well.
You want one page where to show the feeds but you don't want to re-create the template for that page. shallowink told you how to do it and he is right, but, you first have to create the page where you want to display that. Create it and get his ID ( a number ),you can see in the url when you edit it. Then open your page.php file, and where the_content() is called, type after if($post->id=='YOUR_PAGE_ID') { PASTE HERE YOUR CODE } That's it , change YOUR_PAGE_ID with the id of your page.
I think this will work You have 40 urls, Create a page template with the code <?php function My_simplexml_load_file($URL) { $ch = curl_init($URL); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); $xml = simplexml_load_string(curl_exec($ch)); curl_close($ch); return $xml; } ?> <?php $url = get_post_meta($post_id, 'YOUR_CUSTOM_FIELD', $single); if(!$url) { echo "<strong> Feed Unavailable </strong>"; } else { $xml = My_simplexml_load_file($url); if ($xml!=''){ foreach ($xml->channel->item as $item){ $description = $item->description; echo $description; } } } ?> Code (markup): Now you will create 40 pages selecting the same page template, each post will have corresponding feed url in the custom field with name YOUR_CUSTOM_FIELD This way you will not have many page templates on your server