|
Can I have conditional text in a Movable Type template?Dave, I'm awful curious about how exactly you have the PSP book advert that shows up on your pages related to the Sony PSP, but nowhere else on your site. Is that some fancy trick you're doing with Movable Type, or is that some separate bit of programming wizardry you've done? I was just explaining this to a friend, actually, so it's convenient that you ask! When I decided that I wanted to have some material show up conditionally, I figured that I could write a simple Perl script that I'd invoke from my individual archive files and that script would look at the page, figure out what category it was in, and then output additional HTML in the case of a match. Problem was, that's a terrible solution because it's hugely processor intensive and given that I serve up 2-3 pages per second on this server, it'd be a significant burden on the system. Instead, I dug around in the extensive Movable Type Plug-In Library and came across a plugin called Compare. It lets you have conditional code in your templates based on specific equality tests, including testing for what category or categories match the given entry. Even better, it's all processed once as the page or pages are rebuilt: because Movable Type creates static pages rather than dynamically generating pages out of a database on demand, it's also far more processor efficient, meaning that each and every visitor has a better experience as their requested page is served up faster. What's not to like about that? Here's how the code inclusion works. First, just the skeleton:
You can see that it's pretty straightforward, if a bit awkward. Basically just think "if a = b" and you'll get what's going on. The final block of code in my actual individual archive template ends up looking like this:
Hope that helps you get everything working on your own blog.
Categorized:
Blogs and RSS Feeds
(Article 6802,
Written by Dave Taylor)
Tagged: blog customization, blog plugins, conditional HTML, movable type Previous: How do I download music to my RCA Lyra MP3 Player from Mac iTunes? Next: What are the top baby names? Subscribe!
This is now much simpler in MT4.x using the tag: http://www.movabletype.org/documentation/appendices/tags/ifcategory.html I have something to say, now that you mention it, but ...
I do have a comment, now that you mention it!
|
Recommended
Recent Entries
Search
I Need Help!
Apple iPad Help
Articles and Reviews Auctions and Online Shopping Blogs and RSS Feeds Building Web Site Traffic Business and Management CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above Facebook Help Google Plus Help HTML and CSS Industry News and Trade Shows iPhone and Cell Phone Help iPod, Sony PSP and MP3 Player Help Mac OS X Help Pay Per Click (PPC) Advertising Search Engine Optimization (SEO) Shell Script Programming Tech Support Video Help The Writing Business Twitter, LinkedIn and Social Network Help Unix and Linux Help Video Game Tips and Help Windows PC Help WordPress Help |