php

  • Create a Temp/Splash Page in WordPress

    Often times I will be working on a WordPress theme that I want to live test, but I don’t want to reveal it to the world yet. The solution would be to throw up a temp page while you work. However, you may have noticed that throwing an index.html file in the WordPress directory or similar solutions break WordPress. Today I’ll tell you how to get around that.

    (more…)

  • Info Overload- The New Design

    Info Overload Screen

    I hadn’t realized it, but next month will be 2 and a half years since my last redesign, which is considerably longer than my previous time between designs; I was young and impressionable and didn’t know what I wanted. But now something is different. My needs in 2007 were different than my needs now. Then, this was just a place for blog entries (and the occasional trying out a new web dev trick). Now information sharing has increased 10 fold. I have shared thoughts and links on Facebook, Google Reader, Twitter, and here. The new design needs to reflect that, especially since my day-to-day blogging has decreased with the advent of Twitter. I present to you: Info Overload. If you’re in a feed reader, click on through.

    (more…)

  • Directory Handler at Theme Forest

    I’m happy to announce my first Theme Forest component, Directory Handler. it’s a simple set of 2 classes that handle (in several ways) listing the contents of a directory. The main class, DirectoryHandler, includes several functions that:

    • Get and/or print the entire contents of a directory
    • Normalize the name of a file or directory (replace special characters with spaces)
    • Return the extension of a file
    • Return all of the files of a directory in an array
    • Return all of the sub directories of a directory in an array

    TheImageDirectory class extends the functionality of DirectoryHandler by changing the get and print directory functions to:

    • Print a thumbnail version of the image
    • Integrate lightbox for easy image viewing/browsing.

    You can view a live demo here and Download the full documentation here.

  • Learn a Programming Language

    Over at LifeHacker, they are hosting a spirited discussion on what the programming language to learn first is. I think this is a pretty interesting discussion to have and want to comment on what the others are saying, as well as justify my stance. First of all, I did weigh in, saying:

    I’d say if you’re not going to be a serious applications programmer, learn some weak-typed language like PHP or Javascript first to get your feet wet with program logic without having to worry about whether your types (the difference between say a number and a word) are correct. This will help you with the control structures(if statements, loops), how the logic works and how to solve some basic problems. Then you can move on to a more advanced language and learn the different types, objects, etc.

    Many of the others who commented said that Javascript is not a programming language, it’s a scripting language. Is there a huge difference? Maybe, but not to someone first learning. They will not be doing things a programming language calls for- they will be learning control structures and how a program works, what kind of logic goes into writing a program, etc. To be honest, I first learned Java when I was a freshman in college, but I didn’t really understand programming until I picked up PHP over winter break of that academic year. So is there a difference? Sure. Is it a huge deal to someone starting out? Not at all.

    Then we’ve got those who say, “Learn C first, it’s the best” or someone even said, “Learn Assembly.” I know how to program and Assembly is hard. You’re not writing code in something that looks remotely like English and you need an understand of how data is represented on a machine. It sort-of applies for C too, as C is a low level language. Don’t get me wrong, C is the best language I’ve coded in- it’s fast and you can do really powerful stuff. But I think pointers alone is enough to turn someone off to C and programming in general.

    Finally, we’ve got those who say learning an Object Oriented (OO) language is the way to go. I can see that. I feel there is enough abstraction there that the learner might be ok. They shouldn’t dive right into object, however, because objects are pretty difficult to visualize if you’re just starting out.

    I still say my approach is at least a good one. Learning a simpler language that doesn’t put restrictions on data types will allow the learner to focus on program logic more than data representation. They will begin how to think like a programmer and can move up from there. PHP isn’t a bad place to start because it acts like a simple language (weak typed, syntax is pretty easy to understand), but you can do some powerful things like create objects.

    Teaching yourself to program is a pretty daunting task to begin with. However, if you pick up a good book and start with a simple language, you should be fine.

    PS- HTML is not a programming language. It’s a Markup Language. You will not learn anything about programming.

  • New Design- Dynamics

    This is part 3 of 5 of the mini series for my new design. In this part I will be talking about the dynamics of the site and using WordPress as a Content Management System (CMS).

    A change made more on the back end of this site is all of the pages on the site can now be edited through WordPress. This makes it much easier when I want to update things like my resume, the about page, etc. One of the reasons I never did this before was I did a lot of PHP stuff on the seemingly static pages, and there was no way for me to integrate PHP code via the WordPress admin panel. To fix that problem, I found a plug-in called runPHP.

    This handy little plug-in ads a check box to each post asking if I want to run the post or page thought the PHP preprocessor. All I do I add in the php code (with normal tags) and I’ve got dynamic, easy to update pages. This comes especially handy on my projects page, which calls a number of custom functions. With runPHP I can easily change parameters or function calls right from WordPress.

    On the same token, my projects page is also completely dynamic. I will talk more about the plug-in I wrote in the next series, but I would like to touch on the fact that this was something I had been planning for a while. I needed an easy way to add, edit and delete projects from my resume site, Casabona.Org. With WordPress, I was able to add another set of pages to the admin panel to do just that. In the coming months I will be combining Casabona.Org and this site, making them fall under one roof. This plug in will make it much easier for me to manage my projects.

    Using the power of WordPress, I am able to quickly and easily manage my site, transforming the open source blogging system into a CMS. Now, this site is updated more frequently with some very rich content.

  • Uploading Images in PHP

    After dabbling in PHP for some time, and writing an image upload script about 8 months ago, I would like to post it here, with a short tutorial. I have recently reused the script and a friend of mine asked how he would go about doing such a thing. My upload script, to begin, is a function in PHP that returns the path of the image file, which I then add to a database.

    The first thing you must do is set the form up correctly. along with the form name and method (for this, method="post"), you have to specify that you are uploading more than text. Simply add enctype="multipart/form-data" in the form tag. Second, you have to set the permissions on your server to allow uploads. You have to set the Permissions to “777” or Read, Write, Execute for Owner, Group and Public (or World).

    Permissions Image

    Now onto the function. While processing the form, all you do is add something like $image= upload_pic($picName);. This calls the function upload_pic(), passing the argument $picName. The following is an image with well documented code explaining what is going on. For some reason, WordPress doesn’t like it when I code right in the post. At the bottom of the post is a .txt file with all of the code in this post.

    Upload Image Image

    Here is the .txt file with all of the code shown above. If you have any questions, or feel I missed something, be sure to comment on it! Later.

  • Writing a User log-in

    Here is the user login code I have been promising. It’s an image so it looks nice. You can download it at the bottom of the post. Keep in mind- This must be placed before the head tag in the page so if cookies are created, they can be…

    This might not be the most efficient code, but it does work. To get the actual code, click here. And if you do make it better, please let us know in the comments! Later