Page 1 of 1

Strengthening my WordPress-As-Mini-CMS Skills

Posted: Mon Apr 06, 2009 11:55 am
by supermike
Some people overhaul WP from being a blog engine and into a simplistic CMS. Basically they stick with Pages and don't use Posts or Comments, and comment those features out.

Okay, fine, but the problem I'm having is that a client gives me a PSD image of what he wants. So, I'm trying to see if there's a recommended tutorial (or set of tutorials out there) to help me learn the WP object model so that I can convert his PSD to XHTML, and then grab the WP object model to pull in content as I see fit, rather than customizing an existing theme.

What do you recommend?

Currently I've been using the various free theme generators out there, or finding a free theme that is close, and then customizing the heck out of it. I want to do it better, instead.

Note: I don't use WP plugins. Instead, I just use string replacement like look in a Page for

{CONTACT-FORM}

and do a search/replace with my page hook code.

I also have hidden pages where if the page name starts with a certain text, it won't show up in the top navigation, but when I do switch or post to that page, it will pull out that text. For instance, I could name a page: "hide Thank You" and it would not have top navigation.

Re: Strengthening my WordPress-As-Mini-CMS Skills

Posted: Mon Apr 06, 2009 3:42 pm
by alex.barylski
Do you have to use wordpress? Can you not go with another CMS? Have you looked at OpenSourceCMS?

Re: Strengthening my WordPress-As-Mini-CMS Skills

Posted: Mon Apr 06, 2009 3:49 pm
by greyhoundcode
I use WP a lot precisely because it is so easy to theme. If you can create your (X)HTML skeleton, the rest is child's play once you've tuned into the WP way of life.

Check out WPDesigner's tutorial, it really does break it down to brass tacks (perhaps too simplistic in places), but it is a fantastic starting point nonetheless and in concert with the Codex for more advanced features you'll learn pretty much all you need.

All you will really be dropping in is some pretty standard stuff such as The Loop and wp_list_pages() functions, which are the bread and butter of WP - there are numerous examples all over the web.
Note: I don't use WP plugins. Instead, I just use string replacement like look in a Page for

{CONTACT-FORM}

and do a search/replace with my page hook code.
I'm not ignoring your comment about not using plugins, but if you are willing to learn how to write a plugin then WP's shortcode system is a better alternative to the above approach. Similarly, I would recommend using custom fields to indicate those pages you do not wish to appear on menus etc.

You'll find numerous comments on these forums suggesting that WP is unsuitable for use as a 'CMS', and that the code is somewhat suspect, so I'm probably a bit of a lone voice in advocating its use, however if your aim is to rapidly produce and deploy a presentable website that your client can easily update by themselves, then it is an excellent choice.

Re: Strengthening my WordPress-As-Mini-CMS Skills

Posted: Mon Apr 06, 2009 4:38 pm
by supermike
My web designer wants to stick with WordPress. He'll be the one doing the content updates.

I finally found a great tutorial here:

http://www.jestro.com/web-design/conver ... wordpress/

As for shortcodes, it seemed like far too much work to achieve what you want after I looked at how they do this and expose it. My fix, after I followed the tutorial from jestro.com (above), was to edit my index.php. Where I have the call for "the_content(...)", I replaced it with:

Code: Select all

<?php include(TEMPLATEPATH . '/content_hooker.php'); ?>
Then, in content_hooker.php, I put:

Code: Select all

<?php
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
// HOOK THE $content ANYWAY YOU WANT BEFORE BEING DISPLAYED, INCLUDING
// DOING SEARCH AND REPLACE AND LOAD SOMETHING
function replaceCallback($asMatches) {
    return file_get_contents(TEMPLATEPATH . '/hook-' . $asMatches[1] . '.php');
}
$content = preg_replace_callback('/\{([A-Z0-9]+)\}/', replaceCallback, $content);
// END HOOKS
echo $content;
 
So now I can create all kinds of {VAR} stuff extremely easily, and just drop a "hook-VAR.php" file (where VAR is an alphanumeric variable name) in my template folder for my template. This replaces {VAR} with whatever PHP/XHTML/CSS/Javascript/jQuery content I want.

Re: Strengthening my WordPress-As-Mini-CMS Skills

Posted: Tue Apr 07, 2009 2:33 am
by greyhoundcode
supermike wrote:As for shortcodes, it seemed like far too much work to achieve what you want after I looked at how they do this and expose it.
Fair enough, personally I just modify a plugin template for this kind of work.

In your initial example, you were searching and replacing to produce a contact form. But what about dealing with the submitted data? Obviously you'll write more code and stick it in another file to include(), or add it to content_hooker.php, but really aren't you simply reinventing a wheel that WP already provides?

The good thing about plugins is that they can have a presence on the dashboard, so the client could add or subtract fields on the contact form for instance, or ban certain IP addresses or whatever, all from a nice and comfortable admin panel. But of course if you know its never going to develop that far I guess it doesn't matter.
supermike wrote:

Code: Select all

<?php include(TEMPLATEPATH . '/content_hooker.php'); ?>
As a side note, not that it makes a massive amount of difference, but if you place custom functions in your theme's functions.php file they are loaded automatically.

Re: Strengthening my WordPress-As-Mini-CMS Skills

Posted: Tue Apr 07, 2009 10:02 am
by supermike
Didn't know about the functions.php file. Thanks!

In the case of the plugin with a dashboard presence -- I'm kind of taking an easy-out approach due to time constraints and costs.

Oh, and I found a one line, faster approach than to have to use the callback:

Code: Select all

$content = preg_replace('/\{([-A-Z0-9]+)\}/e','file_get_contents(TEMPLATEPATH . \'/hook-$1.php\')',$content,1);
First off, what I have done is to intercept "the_content()" that is normally called to draw the content on the page. I cut and paste that function (found with grep) into an include that gets called from index.php, rather than call "the_content()". I then put the above statement right before the "echo $content;". It looks for something like {CONTACT-FORM} in the code, and then loads 'hook-CONTACT-FORM.php from the template path. Inside the contact form's PHP page, I use jQuery and AJAX to post the form back to a file in the template path file and return an inline form validation result of "Thanks", or "Error".

Re: Strengthening my WordPress-As-Mini-CMS Skills

Posted: Tue Apr 07, 2009 12:42 pm
by supermike
PCSpectra wrote:Do you have to use wordpress? Can you not go with another CMS? Have you looked at OpenSourceCMS?
I spent about two hours doing that a few days ago. Most are mismatches for me -- either too amateurish, too fancy, too quirky, or are written for programmers or slightly technical people instead of non-technical clients who barely know how to use more than a word processor. I liked FrogCMS a good bit as far as its interface, but it lacked TinyMCE or FCKEditor as the rich editor, and had other quirks I didn't like. I think, ultimately, that I will want to get my MVC framework to a reasonable level, my DB class to a reasonable level, and then start to build nothing but a CMS Admin system. I think CMS's should only be an admin system and then provide a cookbook API, easy to understand and use (and to override) that lets you pull stuff out of the database and populate any XHTML/CSS template. I think CMS's should "get over themselves" as far as trying to provide a front-end as well. This is because most people I know don't like the default front-ends and wish they could do it their own way, where even a theme change isn't suitable for them.

But for now, I'm going with WordPress because my sales guy (slash web designer) has market traction with it and because there's a lot of well-written tutorials for it, although I still keep wanting to know more, or compare notes on what other people are doing to customize it.

Re: Strengthening my WordPress-As-Mini-CMS Skills

Posted: Tue Apr 07, 2009 4:00 pm
by matthijs
It's not clear to me why you need to go through all those loops to replace a {contactform} tag with a contact form. If you use the default template functionality you don't need all that. Copy paste the default page template in a new contact page template, add your regular php form processing code and you're done. Then the normal wp loop is still available for the client to add/edit the normal content on that page

Re: Strengthening my WordPress-As-Mini-CMS Skills

Posted: Tue Apr 07, 2009 9:46 pm
by supermike
matthijs wrote:It's not clear to me why you need to go through all those loops to replace a {contactform} tag with a contact form.
The tag technique lets the designer and/or author move stuff around. With a page template, he has no control over that because it's hard-coded in the PHP.

Re: Strengthening my WordPress-As-Mini-CMS Skills

Posted: Wed Apr 08, 2009 1:34 am
by matthijs
That's true. Then it is a matter of deciding when that is needed or not. If the design doesn't really need that flexibility, I would just hardcode it. Otherwise your method or the wp shortcode is the way to go.