Tumblr User Post Retrieval Script

What it does
The script I wrote gets a tumblr users posts from an XML file. With this infomation the script then loops through a set number of most recent posts.
Why I made it
The way I used to keep the "updates" and blogs going before was tedious. I had to move entries to seperate pages and rewrite the code for each new post every time I said something. Now all I have to do is post something on the account and it automaticly show up on the feed.
How to use
You should understand some PHP before using my script, but it will work without any knowledge of it; you just wont be able to customize it much. Paste this entire code box into the place on your site were the feed is going to be.
include 'https://dev.thecubecast.com/PHP/tumblr.php';
Tumblr_Read('TUMBLR_USERNAME', 6);

First Line
The first line include 'https://dev.thecubecast.com/PHP/tumblr.php'; does one important thing, it calls the file containing the script. Scroll down to "Customization" if you would like to customize it.
Second Line
The second line Tumblr_Read('TUMBLR_USERNAME', 6); runs the function that does all the magic. just change the 'TUMBLR_USERNAME' to the profile and the 6 to however many posts you want loaded.


To do any of this your going to have to download the files.
The CSS is very simple, as its not doing the heavy lifting. All it does is give it font colors and background colors. Customize it to your imagination, just keep the css tags.


Now we can get into the good stuff. Now I've only been using php for about a week now, so I am in no position to teach you how to do any of this. Although I can explain what my code does so that you can use it however you must. The following code is only the "text" post on tumblr, The others are in the code but you should be able to figure out how to customize them from this.
	$request_url = 'https://'.$user.'.tumblr.com/api/read?start=-1&num='.$amount; //get xml file
	$xml = simplexml_load_file($request_url); //load it
	if ($xml->posts->post[$x]['type'] == 'regular') {
		$title = $xml->posts->post[$x]->{'regular-title'}; //load post title into variable $title
		$post = $xml->posts->post[$x]->{'regular-body'}; //load post body into variable $post
		$timestamp = $xml->posts->post[$x]['date-gmt']; //load timestamp of post into variable $timestamp
		$output = substr($post,0,-1); //make the post useable for output
		echo // Output the variables above in some html
			'<div id="Update_Wrapper"> <!-- Holds each individual post -->
				<h2 style="text-align:center;">'.$title.'</h2>
				<div id="Update_footer"><br>'.$timestamp.'</div>
			</div> '
To make any sense of what the above code is doing, take a look at what a basic text post from tumblr's XML file would look like.
<post id="15234523452345" url="https://user.tumblr.com/post/15234523452345" url-with-slug="https://user.tumblr.com/post/15234523452345/finished-up-the-new-update-feed-also-added" type="regular" date-gmt="2016-04-30 18:23:09 GMT" date="Sat, 30 Apr 2016 14:23:09">
<p>This is the first paragraph of the post. </p><p>The Second Paragraph</p>
Let's say that a user named "user" made a post. This particular post has not title, or tags. In the above PHP code the first two lines retrieve the link to a users XML page containing all their most recent posts. The if statement below checks if the post is a regular (text) post or 1 of the 6 other types. In this case its a regular post so the if statement will run. Each following line looks through the file using SimplePHP and asigns what it finds to a variable. The echo statement at the end of the if statement puts the respective variables into html that will make the text drawn from the XML look decent.

Each type of post has different types of XML tags. Only 4 of those types are included in this script. To add the other ones take a look at how SimpleXML is used and what the XML file of that type of post looks like. Good luck making this script your own!

What got us through all this
I never would have been able to figure all this out on our own. If it weren't for these websites and editors I never would have got this working. Thanks and here they are.
PHP Manual Documentation of SimpleXML in php.
StackOverflow "Tumblr API in PHP File structure" asked by Dave on December 6, 2013.
StackOverflow "Integrating tumblr blog with website" awnser by Coasta on November 3, 2011
StackOverflow "tumblr PHP file_get_contents html not running" awnser by Chaim on May 2, 2016