That’s right. I turn 42 this month and there’s a MacBook and Adobe CS3 Web Standard on the way.
I’m so stoked I could crap my pants.
Oops, I think I just did. Gotta go.
As Much PHP As Humanly Possible
That’s right. I turn 42 this month and there’s a MacBook and Adobe CS3 Web Standard on the way.
I’m so stoked I could crap my pants.
Oops, I think I just did. Gotta go.
Let’s see . . . after cutting my teeth on Code Igniter, I got into several popular Javascript libraries, and, then, after recently making the switch from XP to Ubuntu, I decided to check out Django.
It was weird; I actually learned more about MVC in regards to PHP and Code Igniter by learning some Python in Django. I’m still a long way from really having a firm grip on the whole thing, but I’m starting to see some real progress in my understanding.
I tell you, though; I wish I had known more about straight PHP functions before I got into frameworks, but it’s been too interesting to complain.
Working from the command-line has really improved my typing skills, too!
This morning I took another look at SVG. I downloaded Inkscape a while back, thinking it was Freehand/Illustrator for Linux. It’s similar in some ways, but the fact that there’s code that can be used to manipulate things has caught my interest. There’s a pretty good introductory tutorial on the Opera Developer website.
Other than that, I’ve spent a lot of time drinking coffee and working on my graphics skills. The Gimp is nice, but it takes a little time to get used to where everything is (I’m used to Fireworks) and establish some kind of work-flow.
Anyway, I’ve neglected this blog for too long, and I felt bad for hurting its feelings. So there it is.
How to get your Pages to appear in either the top Menu or the Sidebar
Note 1: I’m using WordPress 2.1 and the K2 Theme
Note 2: The line numbers apply to the K2 Theme (095rc1)
Note 3: Some of the code formatting is a little weird, but you’ll get the idea.
I ran into a situation that’s easy to fix, and wanted to share a solution.
I really like the K2 Theme, but one thing I noticed was that every Page I created only appeared in the top Menu. That’s the way the K2 guys made it work, and that’s cool, but things get weird if you have more than 4 or 5 Pages, especially if the Page names are more than 1 word.
So I got into the code to see if I could split things up and send certain Pages to the top Menu, and others to the Sidebar. It’s a pretty easy fix, and can be done with the ‘exclude’ argument and a few extra lines of code.
Here’s how it works:
Step 1
Open your administration panel and make a note of the ID associated with each page you have. (That’s in Manage > Pages just to be clear). Determine which pages you want to be visible in the Menu, and which you want in the Sidebar.
Step 2
Open wp-content/themes/K2/header.php
On line 86, change
<?php wp_list_pages(’sort_column=menu_order & depth=1 & title_li=’); ?>
to
<?php wp_list_pages(’exclude=8 & sort_column=menu_order & depth=1 & title_li=’); ?>
By using the exclude=* argument (in my case, the Page with an ID of 8), that Page will not appear in the top Menu.
Note: If you want to exclude multiple pages this way, seperate the numbers with commas, no spaces, and in numerical order, like this: exclude=1,4,6,9 not exclude=4,1,9,6. See the Codex for more specifics.
That’s cool, but I do want that Page to appear somewhere, and I want it to be the Sidebar. So let’s add some code to make it do that.
Step 3
Open wp-content/themes/K2/sidebar.php
Around line 140 or so, add
<?php /* Pages */ if ( (is_home()) or (is_search() or (is_404()) or ($notfound == ‘1′)) or (function_exists(’is_tag’) and is_tag()) or ( (is_archive()) and (!is_author()) ) ) { ?>
<div class=”sb-latest”>
<h2><?php _e(’Pages’,'k2_domain’); ?></h2>
<ul>
<?php wp_list_pages(’exclude=2 & sort_column=menu_order & depth=1 & title_li=’); ?>
</ul>
</div>
<?php } ?>
I chose this location because I wanted the Pages that aren’t visible in the top Menu to be visible under the ‘Latest Entries’ (posts) in the Sidebar, and I just copied the code-block for ‘Latest Entries’ (line 128) and pasted it underneath itself. Then I modified part of the new code-block, which originally looked like this:
<ul>
<?php wp_get_archives(’type=postbypost & limit=10′); ?>
</ul>
and made it look like this:
<ul>
<?php wp_list_pages(’exclude=2 & sort_column=menu_order & depth=1 & title_li=’); ?>
</ul>
I changed wp_get_archives to wp_list_pages, and again, I used the exclude=* argument (in my case, the Page with an ID of 2) to show the Page that was not visible in the top Menu, and make it visible in the Sidebar. (The other arguments can be changed to suit you, see the Codex for details). The original code-block for ‘Latest Entries’ also contained a <span> tag with some additional code for an RSS feed, but I left that out of my new ‘Pages’ code-block because I didn’t need that functionality. I also used the same CSS class as ‘Latest’ for my new ‘Pages’, but you could write a new CSS class if you want it to look different.
That’s pretty much it.
This example works, but it has the potential to get weird if you have a lot of pages. Personally, I like pages, and plan to use a lot of them in my next project. So my next experiment is to get a checkbox or something in the administration panel that will allow me to select a destination for each new page (i.e., Menu or Sidebar, maybe both). But it’s still early in the game, so I might discover a better solution (there may even be an existing plug-in out there already; I haven’t even looked). Either way, I’ll post the result here when I have one.
To change the word ‘Blogroll’ to ‘Links’ in the Administration Toolbar:
Note 1: I’m using WordPress 2.1
Note 2: The line numbers apply to the K2 Theme (095rc1)
Note 3: Optionally, you can copy each line to be modified and paste it under the original, then comment-out the original so you can revert later, if necessary.
Step 1
Open wp-admin/menu.php
On line 19, change
$menu[20] = array(__(’Blogroll’), ‘manage_links’, ‘link-manager.php’);
to
$menu[20] = array(__(’Links’), ‘manage_links’, ‘link-manager.php’);
This will change the top part of the menu. Save the file, and load your page to see the effect.
Step 2
Open wp-admin/link-manager.php
On line 19, change
$title = __(’Manage Blogroll’); to $title = __(’Manage Links’);
to
$title = __(’Manage Links’); to $title = __(’Manage Links’);
This will change the sub-menu. Save and reload your page to see the effect.
Step 3
On line 75 (still in link-manager.php), change
<h2><?php _e(’Blogroll Management’); ?></h2>
to
<h2><?php _e(’Link Management’); ?></h2>
Save and reload your page. You know why.
Step 4 (Optional)
On line 76 (still in link-manager.php), re-write the description to whatever you want. It’s all inside this tag:
<p><?php _e(’Here you…’); ?></p>
That’s it. All done. Everything just says ‘Links’ instead of ‘Blogroll’.
“But, why” you ask? Because I love blogging, but the word we use to describe it annoys me. Say it a few times; it’s like when you a piece of bread stuck to the roof of your mouth. Anyway, Happy Blogging! [pukes in trashcan]
Concerning the recent turn of events I’ve outlined in my previous post ‘Unbelievable’, let it be known that help is never far away.
The help I needed to fix my particular problem came in the form of ‘WordPress Complete’ by Hasin Hayder. More specifically, Chapter 5: Non Blog Content, which is freely available as a downloadable pdf from Packt Publishing.
This single chapter showed me how to modify WordPress in such a way that I could use it both for presentation, and as a workable content management system. Following Hasin’s excellent step-by-step instructions, I had a rough outline of what I needed in 2 hours. After that, I was able to produce in 3 days what took me 3 months to accomplish on the .Net platform. Granted, I was already familiar with PHP and the WordPress engine to a fair degree (much more than I knew about Asp.Net, at least), but the time and trouble that was saved from reading that one chapter was truly incredible.
I can’t wait to read the rest.
Hasin, if you happen to get here one day, I just have to say that you saved my ass, and I can’t thank you enough. I’ll be purchasing the full pdf and a hard-copy version of your book as soon as I get paid for this job. You’re the man.
Back to The Loop.
The subtitle of this blog is “As Much PHP As Humanly Possible”, and it turns out that it couldn’t be more appropriately named.
Although my first ventures into the world of creating database-driven websites were using the great Apache/PHP/MySQL combination, a few months ago I took a job building a website for a friend/client with the intention of using IIS/Asp.Net 2.0/SQL 2005.
It’s turned out to be a great learning experience, and I’m glad to have the extra skills in this area.
But something happened today that hastened my return to the open-source way of doing things. I’ll call it ‘absolute necessity’.
You see, when we first discussed overhauling the existing static HTML site, my original intention was to rebuild it using PHP with a MySQL database, which, as you know, is a good thing. However, to address some concerns about possible security breaches passed on to friend/client by the person in charge of the current web-hosting, I suggested that perhaps it was time to switch to a hosting company that had moved out of the dark ages. Don’t get me wrong; hosting several hundred thousand static HTML pages (complete with pale-yellow backgrounds and animated gif’s) on Apache 1.0 is still a viable way of presenting content, but since friend/client is in the business of presenting high-resolution images and HD quality video to paying members, we both thought we could do better with a web-host that would provide some room for a growing business.
Within days of our initial conversations, I had started playing around with the .Net Framework, mostly because Microsoft had released Visual Web Developer and SQL 2005 Express (along with a bunch of SDK’s) for free, and later suggested using .Net to build the new database-driven website. The primary concern at this point was building a content management system that a non-tech type could use to upload images and video, and add basic descriptions for the products via a rich-text editor (much like the WordPress interface I’m using to type this), and be done with it.
Besides, I wanted to learn Asp.Net, and this was a great opportunity to put it to use.
The work began around November 1st 2006, and we were looking to start testing the site on a new dedicated server this coming weekend – roughly February 1st 2007. Not too shabby considering I knew nothing about Asp.Net when I started.
My only real concern during the development was how much trouble it was going to be to roll the SQL 2005 Express database over to a real Enterprise version.
I should point out that friend/client and I have kept our communications to a bare minimum, as requested by friend/client. I thought, “That’s cool. Who wants to hear a bunch of techno-babble, anyway?”
Yeah, I know. You already see what’s coming, so I may as well get to the meat of the subject.
The new server rocks. I just checked out the cPanel an hour ago.
It’s an Apache server with a MySQL database. The .Net application will never see the light of day – not on this server. I don’t know how much PHP is humanly possible, but it looks like I’m about to find out.
As of this writing, I have yet to break the news to friend/client.
I have so much work to do, it’s unbelievable.
Uno.