In Praise of Wordpress Template Tags, Part II: The Magazine Layout

In Praise of Wordpress Template Tags, Part II: The Magazine Layout

July 24, 2007 ( 265 )

Previously, we saw how Wordpress can capably handle data more like a small-scale CMS than a traditional blog, assuming the developer is willing to get creative with some Template Tags and The Loop. With that in mind, let’s move toward a more sophisticated homepage concept.

Sample scenario: a client needs your help in realizing his dodgy dream of starting an online men’s magazine in the vein of GQ or Details. His existing site already runs the standard Wordpress blog format, but now he’s seeking a more ambitious, exploded-view layout to accommodate a variety of content modules and features somewhere between Nirali and Talking Points Memo.

With his love of hair gel, gossip and designer messenger bags, it’s not surprising our client’s new publication will be called Mimbo. He’s even sketched out a wireframe for the homepage (click for demo):

mimbo

It’s nothing too polished yet, just a grid-based concept illustrating the main content components we’ll need to tease out of Wordpress: “Lead Story”, “Last Three Features”, “News”, “Contributors” and so on. How do we tie all this together on one page? Let’s start at the top and explore each module step by step:

  1. Logo and TaglineIn the upper corner of Mimbo’s layout, you’ll see our branding which is really just the site title (”Mimbo”) and tagline (”by men, for men”) and can be edited from the control panel:

    tagline

    The functions are standard to any Wordpress installation and can be added to your page like this:

    <a href="/"><?php bloginfo('name'); ?></a>
    <?php bloginfo('description'); ?>
    
  2. Search moduleYou probably already knew that the search bar in the upper right corner originates from a PHP-include which looks like this:
    <?php include (TEMPLATEPATH . '/searchform.php'); ?>
    

    You can always style the search bar to your liking, or create a custom search page.

  3. Lead Story ModuleEach issue of Mimbo will feature a Lead Story module with a photo, a category title, an article title and an excerpt.

    Let’s start with the photo. First find an appropriate image and resize it to 269×178. Next, upload it to the correct folder (example: /wp-content/themes/mimbo2/images/).

    Now I’ll begin a new post and create a category called “Lead Story”:

    After writing my post, I will scroll down to the “Custom Field” box. I’ll need to name the Key “Image” (with a capital “I”) and my Value will simply be the filename of that image:

    Before saving our post, know that the the_excerpt function will automatically pull the first 55 words from our post. If you’d like to provide alternative excerpt text, just fill in the “Optional Excerpt” field:

    When you’re done, save the post. Now, what PHP magic must happen to print it all to the homepage?

    <?php query_posts('showposts=1&cat=3'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
    <img src="<?php echo get_option('home'); ?>/wp-content/themes/mimbo2/images/<?php
    // this is where the Lead Story image gets printed
    $values = get_post_custom_values("Image"); echo $values[0]; ?>" alt="" id="leadpic" /></a>
    <h3>
    <?php
    // this is where the name of the Lead Story category gets printed
    single_cat_title(); ?>
    </h3>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>" class="title">
    <?php the_title(); ?>
    </a>
    <?php the_excerpt(); ?>
    {<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">More&raquo;</a>}
    <?php endwhile; ?>
    

    In the query_posts function at the top, you’ll notice a parameter called “cat=3″. That id number will differ from user to user, depending on what number is assigned in your database. It can be viewed in your control panel under Manage->Categories:

    Be sure to adjust yours accordingly.

  4. Three FeaturesIn the lower left column, you’ll see three Feature boxes containing a photo and a title. Just like with the Lead Story, we’ll need to create a new category called “Features”, use Custom Fields to input the images, and pull it all together with Template Tags:
    <?php
    // this is where the Features module begins
    query_posts('showposts=3&cat=4'); ?>
    <h3>
    <?php
    // this is where the name of the Features category gets printed
    single_cat_title(); ?>
    </h3>
    <?php while (have_posts()) : the_post(); ?>
    <div class="feature">
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
    <img src="<?php echo get_option('home'); ?>/wp-content/themes/mimbo2/images/<?php
    // this is where the custom field prints images for each Feature
    $values = get_post_custom_values("Image"); echo $values[0]; ?>" alt="" /></a><a href="<?php the_permalink() ?>" rel="bookmark" class="title">
    <?php
    // this is where title of the Feature gets printed
    the_title(); ?>&raquo;</a></div>
    <?php endwhile; ?>
    
  5. Category BlurbsIn the lower middle column, you’ll see there are categories like Music, Style and Gadgets. For each we want to pull a photo, a title and an excerpt. Instead of duplicating the same Template Tags for each category, we put the categories into an array and pull them like this:
    <?php
    // this is where you enter the IDs of which categories you want to display
    $display_categories = array(5,6,7);
    foreach ($display_categories as $category) { ??>
    
    <?php query_posts("showposts=1&cat=$category"); ??>
    <?php
    // this is where you enter the IDs of which categories you want to display
    $display_categories = array(5,6,7);
    foreach ($display_categories as $category) { ?>
    
    <?php query_posts("showposts=1&cat=$category"); ?>
    <h3><?php
    // this is where the category name gets printed
    single_cat_title(); ?></h3>
    <?php while (have_posts()) : the_post(); ?>
    
    <?php
    // this grabs the image filename
    $values = get_post_custom_values("Image");
    // this checks to see if an image file exists
    if (isset($values[0])) {
    ?>
    
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
    <img src="<?php echo get_option(’home’); ?>/wp-content/themes/mimbo2/images/<?php $values = get_post_custom_values("Image"); echo $values[0]; ?>" alt="" /></a>
    <?php } ?>
    <a href="<?php the_permalink() ?>" rel="bookmark" class="title"><?php the_title(); ?>&raquo;</a>
    <?php the_excerpt(); ?>
    <?php endwhile; ?>
    <?php } ?>
    
  6. News HeadlinesAt the top of our sidebar are three headlines from the “News” category. You may have already guessed that we need a new category called “News” and another query_posts function:
    <?php query_posts('showposts=3&cat=8'); ?>
    <ul>
     <?php while (have_posts()) : the_post(); ?>
          <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
     <?php endwhile; ?>
     </ul>
    
  7. Browse ArchivesBecause the archive list can become very long over time, we will display ours in a pull down menu:
    <form id="archiveform" action="">
    <select name="archive_chrono" onchange="window.location =
    (document.forms.archiveform.archive_chrono[document.forms.archiveform.archive_chrono.selectedIndex].value);">
    <?php get_archives(’monthly’,”,’option’); ?>
    </select>
    </form>
    
  8. Ads & Sponsors (Optional)If you wish to insert advertising, open sidebar.php and add whatever code is needed.
  9. ContributorsLast comes our “Contributors” module which uses the wp_list_authors function to query our database for contributors, print them in a list and include an RSS link for each:
    <ul>
     <?php wp_list_authors('exclude_admin=1&show_fullname=1&hide_empty=1&feed_image=/wp-content/themes/mimbo2/images/rss.gif'); ?>
    </ul>
    

    Using a few available parameters, I have opted to exclude myself (administrator) from the list, show the name of each author, hide the name of any author who has not published anything and display an RSS icon.

  10. Single Post PagesIf you view a single post, you will see author info at the bottom of the article. That info can be edited in the control panel under Users->Your Profile.

    The author’s photo uses a custom field to display the image. Note that the filename must match the author’s last name (ex: “Hoyt.jpg”):

    <img src="<?php echo get_option('home'); ?>/wp-content/themes/mimbo2/images/<?php the_author_lastname(); ?>.jpg" alt="" />
    

    The author’s name is called like this:

    <?php the_author_posts_link('namefl'); ?>
    

    The author’s bio is called like this:

    <?php the_author_description(); ?>
    

    The author’s email is called like this:

    <a href="mailto:<?php the_author_email(); ?>" title="Email this author">Email this author</a>
    

That seems like a pretty good start to our magazine empire. Now it’s up to the client (himself a confirmed mimbo) to hire some talented writers and hope for the best.

Popularity: 18% [?]

265 Responses
  1. Darren,
    This is a terrific series — I’ve been looking for ages for a CMS to handle this type of thing for a local project: if only I’d known sooner that the mighty WordPress could handle this type of thing.
    Keep up the good work - can’t wait to see what you have coming next.
    Cheers - GD

  2. Pierro said:

    wow - brillant.
    thats why i need a own wordpressblog, because
    I use at present a freeaccount on wordpress …

  3. Great idea - one question, don’t feeds pull the excerpt? If so, they’d be pulling the image and not the post?

  4. This is awesome. A template would come in handy for my podcast site. My only question would be if the Lead Story Blurb could also display the Podpress plugin media player for podcasting.

  5. I’ve done a couple of “WordPress as CMS” projects for clients and the first few were a bit of a battle. They’ve gotten easier but I think this post will ratchet up my dollars to effort ratio a bit more.

    Thanks!

  6. Lindsey said:

    This is one of the best, easiest to read and understand WordPress template articles I’ve ever read. I’d venture to even say the best I’ve found so far. Thanks for breaking it down so easily and giving me tons of great ideas!

  7. Darren said:

    Thanks for the feedback, guys.

    @ Brian: Wordpress feeds can show the entire post unless specified by the feedreader, in my experience, at least that’s what I’ve found with Netvibes, Bloglines and Google Reader. If I go ahead and create a working theme for the magazine layout, I’ll do some testing and see how the RSS issues pan out.

    @ Kris: Far as I know, the Podpress/Flash bit appears at the bottom of full posts, but isn’t included in post excerpts or “Read More” snippets. Again, that’s something I’d be interested in testing out.

  8. Miriam said:

    This is an excellent description of how to use WordPress as a CMS? I use WordPress for CMS sites for clients, since it’s so flexible. But I never even thought of using it like this, and some of the things you describe here are new to me. Thanks for such an informative post!

  9. waaah said:

    poor wordpress. it wants to be a CMS so badly, but the admin code is so awful and static. broken dev process, old code.
    i really wish someone would come with a more flexible blog-as-a-cms package and knock wordpress off.

  10. Matt said:

    I’d just like to add a voice saying, absolutely convert it to a theme if you’re able to and have the motivation. It’d be a brilliant addition to the Wordpress world.

  11. Chris said:

    Hi, I’d also definitely be really glad if you could find the time to convert it to a theme (it’s pretty well just what I need for a site I’m working on), but a great article either way!

    Thanks!

  12. Darren said:

    Hi guys,

    Technically the first part of the theme is already written; it’s what I used to test a lot of the functions described in the article. The code is sloppy and full of inline CSS styles, as it was just created for testing purposes, but it worked fine. Check back in a few weeks and I’ll put together a more complete theme available for download.

  13. youyicun said:

    thx!

  14. So I have a question: How do you style each of those Featured Stories boxes? Based on my experience over the past hour trying to do that, it groups all three stories into one div and I can’t (because I’m slightly retarded) figure out how to get a border box around each story separately; it just puts the border and styling around the entire container of the featured stories that are being pulled from the database.

    Can someone enlighten me?

  15. Hello! Good Site! Thanks you! xapemmoodu

  16. Matt said:

    Darren,

    Thanks for the great info!

    I for one would love to see a WP template based on the Mimbo example.

    Best,
    Matt

  17. Darren Hoyt said:

    A ‘Mimbo’ Wordpress theme is in the works. If all goes well, it might be done by Sunday or Monday, check back soon…

  18. I think this could be a great theme!

  19. hi darren,
    thx for this great template - i was looking for sth like this a long long time. but i have the problem, that the more-tag is not working. if i try it in the main-lead-story, the story is always shown in the full length. how can i correct this ?

    thank u in advance,

    the traveler (testblog on http://t1745.foto-outlet.de/wordpress/)

  20. Darren Hoyt said:

    @The Traveler:

    The ‘Mimbo’ theme is now available, and the new version no longer requires the “Read More” function.

  21. eddy said:

    great job on this

    its awesome

Pages: 1 2 3 4 5 6 » Show All

Trackbacks
  1. Quality Peoples » Magazine Layouts with WP:

    [...] how to create a “magazine style” layout using Word Press’ template tags at Darren Hoyt Dot Com. Great tutorial. [via can’t quite [...]

  2. WordPress as an Online Magazine:

    [...] and how great it has been as a content management system. In his latest part entitled “In Praise of Wordpress Template Tags, Part II: The Magazine Layout” he shows how he integrated WordPress into a website, using it to run an online magazine. A [...]

  3. Customizing Wordpress the Easy Way!:

    [...] Darren Hoyt has written an amazing, concise and easy to read WordPress “tutorial” on usi… to customize your Wordpress theme in creative ways to achieve the layout you desire - in this case a magazine style layout. [...]

  4. WordPress 作为一本网络�志 | wordpress blog xqxp.com:

    [...] WordPress and how great it has been as a content management system. In his latest part entitled “In Praise of Wordpress Template Tags, Part II: The Magazine Layout� he shows how he integrated WordPress into a website, using it to run an online magazine. A very [...]

  5. Mit Wordpress ein Online Magazin bauen:

    [...] man aus einer normalen Wordpress-Installation ein Online Magazin, wie GQ und Co., erstellen kann: In Praise of Wordpress Template Tags, Part II: The Magazine Layout. Mit nur wenigen Handgriffen könnt auch Ihr den einen oder anderen Trick aus dem Artikel von [...]

  6. links for 2007-07-27:

    [...] Darren Hoyt Dot Com » Blog Archive » In Praise of Wordpress Template Tags, Part II: The Magazine L… Previously, we saw how Wordpress can capably handle data more like a small-scale CMS than a traditional blog, assuming the developer is willing to get creative with some Template Tags and The Loop. Let’s move toward a more sophisticated homepage concept (tags: wordpress web design cms) [...]

  7. marlyse.com » In Praise of Wordpress Template Tags, Part II: The Magazine Layout:

    [...] (Via Darren Hoyt Dot Com » In Praise of Wordpress Template Tags, Part II: The Magazine Layout. filed under : asides - wordpress | created late at night - it was 11:27 pm to be exact | [...]

  8. Entreprenews of the Week -- Young Go Getter:

    [...] In Praise of Wordpress Template Tags, Part II: The Magazine Layout Magazines have somewhat perfected their format over centuries. A format that happens to work perfectly with blogs. Here’s a guide to making your own Wordpress based online magazine. [...]

  9. links for 2007-07-29 « toonz:

    [...] Darren Hoyt Dot Com » Blog Archive » In Praise of Wordpress Template Tags, Part II: The Magazine L… (tags: wordpress tutorial magazine tutorials howto css) [...]

  10. Basic Thinking Blog » Wordpress als CMS:

    [...] In Praise of Wordpress Template Tags, Part II: The Magazine Layout und In Praise of Wordpress Template [...]

  11. links for 2007-07-30 | MY Vast Right Wing Conspiracy:

    [...] In Praise of Wordpress Template Tags, Part II: The Magazine Layout Sample scenario: a client needs your help in realizing his dodgy dream of starting an online magazine. His existing site already runs the standard Wordpress blog format, but now he’s seeking a more ambitious, exploded-view layout to accommodate a variet (tags: wordpress cms tutorial themes templates webdesign design layouts magazine) [...]

  12. Mine del.icio.us-links den 31. juli:

    [...] In Praise of Wordpress Template Tags, Part II: The Magazine Layout - Brug WordPress til et online-magasin [...]

  13. one digital life » Blog Archive » Tutorial: Magazine layouts with Wordpress:

    [...] traditional blog, and more like an online magazine? Darren Hoyt has you covered with a nice little tutorial on reformatting your Wordpress [...]

  14. 10 Links für ein besseres WordPress-Blog | NanoPub:

    [...] In Praise of Wordpress Template Tags (Part I) und Part II [...]

  15. Recommended Reading for 25th July through 4th August:

    [...] Creating A Magazine Layout For WordPress - Excellent post describing how to create a magazine style homepage for a WordPress blog. [...]

  16. adventures of a blogjunkie » Blog Archive » del.icio.us bookmarks for August 4th:

    [...] Darren Hoyt Dot Com » Blog Archive » In Praise of Wordpress Template Tags, Part II: The … - [...]

  17. links for 2007-07-26 en newdisco:

    [...] Darren Hoyt Dot Com » Blog Archive » In Praise of Wordpress Template Tags, Part II: The Magazine L… Como convertir una instalacion de Wordpress en una revista online. Excelente documento. (tags: wordpress howto tutorial magazine inspiration webdesign webdev cms) [...]

  18. Thème Wordpress Magazine, un soupçon de CMS ?:

    [...] fait un petit moment que je suis le blog de Darren Hoyt qui a entrepris il y a un petit moment plusieurs articles sur les possibilités de customiser Wordpress pour en faire un site complet, de type CMS. [...]

  19. Mimbo Magazine-style WordPress Theme » D’ Technology Weblog: Technology News & Reviews:

    [...] is a new magazine-style Wordpress theme, explained in detail here. It contains no images and only minimal CSS(link) (Cascading Style Sheets) styling. Mainly it [...]

  20. blog do valdecir carvalho » Blog Archive » links for 2007-08-07:

    [...] Darren Hoyt Dot Com » Blog Archive » In Praise of Wordpress Template Tags, Part II: The Magazine L… TUTORIAL SOBRE COMO CRIAR UM TEMPLATE BASEADO EM UMA REVISTA - PODE SER ÚTIL PARA O SITE!!! (tags: blog blogging cms design inspiration hack Magazine theme Wordpress Tutorial Howto tutorials CSS) [...]

  21. Magazine Layout | The WP Journal:

    [...] Category: Tips | ≅ Darren Hoyt wrote an explicit article on turning WP into a magazine style website: It’s nothing too polished yet, just a grid-based [...]

  22. Best of July 2007 | Best of the Month:

    [...] In Praise of Wordpress Template Tags, Part II: The Magazine Layout Sample scenario: a client needs your help in realizing his dodgy dream of starting an online men’s magazine in the vein of GQ or Details. His existing site already runs the standard Wordpress blog format, but now he’s seeking a more ambitious, exploded-view layout to accommodate a variety of content modules and features. The article explains how the solution might look like. [...]

  23. Nachlese Juli 2007- Die Seiten des Monats » Allgemeines:

    [...] In Praise of Wordpress Template Tags, Part II: The Magazine Layout Eine detaillierte Einleitung in die Umsetzung eines Magazin-Layouts in Wordpress. [...]

  24. Best of July 2007 .:

    [...] In Praise of Wordpress Template Tags, Part II: The Magazine Layout Sample scenario: a client needs your help in realizing his dodgy dream of starting an online men’s magazine in the vein of GQ or Details. His existing site already runs the standard Wordpress blog format, but now he’s seeking a more ambitious, exploded-view layout to accommodate a variety of content modules and features. The article explains how the solution might look like. [...]

  25. lost node » Blog Archive » Best of July 2007:

    [...] In Praise of Wordpress Template Tags, Part II: The Magazine Layout Sample scenario: a client needs your help in realizing his dodgy dream of starting an online men’s magazine in the vein of GQ or Details. His existing site already runs the standard Wordpress blog format, but now he’s seeking a more ambitious, exploded-view layout to accommodate a variety of content modules and features. The article explains how the solution might look like. [...]

  26. Mark Kirby - Brighton » Blog Archive » links for 2007-08-14:

    [...] Turning wordpress into a CMS (tags: blogging wordpress) [...]

  27. links for 2007-08-14 | betohayasida.net:

    [...] Darren Hoyt Dot Com » Blog Archive » In Praise of Wordpress Template Tags, Part II: The Magazine L… (tags: wordpress:tutorial) [...]

  28. My del.icio.us bookmarks for August 1st through August 14th:

    [...] Darren Hoyt Dot Com » Blog Archive » In Praise of Wordpress Template Tags, Part II: The … - ????????? ?? ???? ?????? ??? [...]

  29. Post-ferie linkopsamling | Webmercial.dk:

    [...] Wordpress til magasinlayout [...]

Leave a Reply