Monday 20 January 2014

Adventures in the magical world of php

Since creating a new website on the weekend, I have been making one or 2 changes.

In brief the changes are:
1. Icons at the top of the homepage feed for the rss instead of links, it just looks neater I think
2. I changed the date format at the top of the posts so that the day now comes before the month, I don't want to say whether the English or the American dating convention is the right one, but the English way is definitely the right way.
3. There is now a corndog pictures link on the left hand side.
4. There is a losing time link on the left  hand side, but what does that mean?

The main reason for making changes is because I want to challenge myself, much of the site is now in php, which for those of you uninitiated with web coding, is like writing html, except you try and make it write part of the code itself.

PHP I find really confusing, especially compared to html, html is really simple content and so on, you just learn what the tags are and you position them around your page forever, wouldn't it be great if all programming was like html, the whole world would be geniuses in no time, whereas php is all question marks, semicolons and brackets, miss one out and it is broken.

I first used php when trying to update the old version of my website, I had a links bar on the left hand side which is fine if you've got 2-3 pages, but my collection of pages just kept on growing, I had an unnatural and probably an unfair aversion to using frames, so i was on the lookout for a different way, the best way seemed to be with a php page, where I create a simple php page (ok so a html page with a .php suffix) for the links list and use ?php include to pull the links page in. Magical, instant time saver.

I was so taken with this effect that for the new version I created one page for the top and the left and all just include that and the content is just added to the large box part on the right, not only do I have an easy to update links list, but I could change the banner and the colour scheme just as easily.

Now having the php pages was one thing, I had the structure sorted, but I thought, surely I can manage more than one line of php, right? So I created a news feed using a code I found on the internet, it pulled through my newly combined rss feeds and it was there, I couldn't believe what I had achieved! To be honest, not much, some anonymous person from some dark corner of the internet created that, I would have to do some more to feel that same sense of achievement, it become instantly clear that when echoing text and so on into the page, you simply revert to html, oh how things start to become clear then, i could use my favourite visual organisational tool the table quite easily, just start the table fields in the first echo and close the table off in the last one, with a bit of shuffling I got the date onto the same line as the title and with 1 simple line I was able to restrict the body to 1000 characters, so far so good.

Then I came up with another idea, what if my posts worked out which blog they were from, wouldn't that be great? I found the equivalent code for IF functions online and had it read the link field, 4 times one for each blog and it worked! the largest change I had made yet, I was quickly figuring out this php stuff, I was able to replicate this success on a separate news page, where I could remove the link from the top and put it at the bottom as a 'comments' link, no particular benefit to this, something just told me I wanted a separate page for this, to try and differentiate the 2, they are not limited on the news page.

Now that I felt I was coming to understand php (it was delusion, I was not), I thought I wonder what else comes in rss feeds, ooh, what about flickr? I havge a flickr feed, that would be good - Now don't get me wrong, I do not believe that having a pictures page on my website is any better than just linking directly to the flickr photostream, in fact the rss feed only shows the last 20, so it is far less efficient, but I thought I would have a go.

Then I came across a stumbling block, the pictures themselves were in a media:content tag, this was not what I expected, I tried including it in the same way but it didn't work, it turns out this is a namespace and I found some codes I could use, though they were not the same as what I had, all the items I had were listed in 1 $item array, whereas the code I found was to pull through the item by itself. I decided I didn't want to do this, to do this would be to admit I had learned nothing and that the code I had was somehow wrong, I was sure I could turn the line of code into a bit of an array... I could, it was amazing, the result is here, my pictures page.

It turns out that I am of the genuine belief that people want to read about coding, but without any of the pesky advice telling them how to actually do it.

No comments:

Post a Comment