Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have some data that I'm pulling from an XML source and would like to display it in Wordpress.

One solution would be to take the static markup that my theme generates and spaghetti-code my page with some PHP that grabs the data from the XML and prints it in the page. Easy enough, but now every time I make a change to the theme I have to re-apply it to this page.

Is there a more elegant solution that would allow me to inherit the whole site look n' feel and just append my data to it?

Thanks

share|improve this question
    
Do you have some sample code? –  kaiser Aug 23 '11 at 19:07
    
No sample code kaiser. Isn't the question clear? I need to give a standard PHP page the look n' feel of my WP blog, without resorting to copying the markup, which is easy but not very maintainable. –  L. De Leo Aug 23 '11 at 19:14
    
The Q is clear. But it's always easier to show stuff on an example that you can just try out via copy/paste, right? –  kaiser Aug 23 '11 at 19:19

2 Answers 2

up vote 1 down vote accepted

I would make a plugin out of the code that you are using to pull the XML. I've done this before for a client that was using a calendaring system that was a set of PHP files. I wrapped the calls to the calendar files in a plugin, and just called what I needed to from there. This preserved the look and feel of the site without extra work there, and used WordPress's native capabilities.

It's fairly easy to take an existing set of code and wrap it as a plugin, and then you can use the methods of that plugin in your theme files. You could for example make a page to house the data, make a page-specific theme file that outputs (or not) the content of that page, and also use the theme file to run the methods for pulling in the XML data via your plugin.

Resources for writing (or wrapping code into) a plugin:

share|improve this answer
    
Thanks Joshua, that looks like it's a viable option. –  L. De Leo Aug 23 '11 at 20:16

I would suggest writing shortcodes to manipulate your data. You can write a function that dumps your entire output with a neat little code placed in a post or you can go very in depth with shortcodes and give parameters to process or return data differently conditionally.

If it is straightforward and simple enough you can just place it inside your functions.php file. If you start to go in depth with it I would suggest you create a plugin to contain your code instead.

With a shortcode you can create a post that can process your xml and you can insert the data from the elements as so [fromxml element="xml_element"] or [fromxml]xml_element[/fromxml] or [fromxml source_file="myfile.xml" element="xml_element"] and so on...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.