Hit or Miss

Integrated Quicklinks Tutorial 2

After writing my previous tutorial for MoveableType on integrating quicklinks with your main weblog into one column, I absorbed a lot of feedback and other examples and then developed an even better MT template that I’m now using.

My previous template would combine the entries from two weblogs on a strictly date/time order. This new template will arrange the quicklinks into a box at the beginning of each date range (basically sorting by date, by blog ID, and then by time).

The only drawback to this new template is that it requires use of the MTSQL plugin, meaning it won’t work for anyone who’s not using MySQL as their database backend.

  1. Download and install the MTSQL and MTCompare plugins.
  2. In your main weblog, create a new template called “Combined Entries.” The output file should be called “combined.txt” and you should link the template to a file named “combined.tmpl”.

    Paste the following code into the template box:

    <MTSetVar name="openedList" value="0">
    <MTSQLEntries query="select entry_id, entry_blog_id, date_format(entry_created_on, '%Y.%m.%d') as mtdate, date_format(entry_created_on, '%h.%i.%S') as mttime FROM mt_entry where entry_blog_id in (1,2) and entry_status=2 order by mtdate desc, entry_blog_id desc, mttime desc limit 0,20" unfiltered="1">
    <MTDateHeader></p>
    <h2 class="date"><$MTEntryDate format="%B %e, %Y"$></h2>
    <p> <MTIfEqual a="[MTSQLColumn column='2']" b="2" numeric="1"></p>
    <ul class="quicklinkBox">
    <MTSetVar name="openedList" value="1">
    </MTIfEqual>
    </MTDateHeader>
    <MTIfEqual a="[MTSQLColumn column='2']" b="1" numeric="1">
    <MTIfEqual a="[MTGetVar name='openedList']" b="1">
    </ul>
    <p> <MTSetVar name="openedList" value="0">
    </MTIfEqual>
    <!-- regular weblog entry --></p>
    <div class="entry">
    <b class="entryTitle"><$MTEntryTitle$></b><br/>
    <$MTEntryBody$>
    <MTEntryIfExtended> <i><a href="<$MTEntryPermalink$>">Read More...</a></i></MTEntryIfExtended></p>
    <p class="entryPostscript"><$MTEntryDate format="%X"$>
    [<a href="<$MTEntryPermalink$>"><$MTEntryCommentCount$> comments</a>]
    </p>
    </div>
    <p></MTIfEqual>
    <MTIfEqual a="[MTSQLColumn column='2']" b="2" numeric="1">
    <!-- quicklink entry --></p>
    <li class="quicklink">
    <a href="<$MTEntryBody$>" class="quicklinkLink"><$MTEntryTitle$></a>
    <MTEntryIfExtended>: <$MTEntryMore$></MTEntryIfExtended>
    [<a href="<$MTEntryPermalink$>"><$MTEntryCommentCount$> comments</a>]
    </li>
    <p></MTIfEqual>
    <MTDateFooter>
    <MTIfEqual a="[MTGetVar name='openedList']" b="1" numeric="1">
    </ul>
    <p> <MTSetVar name="openedList" value="0">
    </MTIfEqual>
    </MTDateFooter>
    </MTSQLEntries>
    <MTIfEqual a="[MTGetVar name='openedList']" b="1" numeric="1"></ul>
    </MTIfEqual>

    This template works with the assumption that the blog ID of your regaulr weblog is 1, and your quicklink/sidebar weblog is 2. And, depending on the way you have your quicklink/sidebar blog set up (ex, I use the MTEntryBody field to store URLs), you may need to tweak the template format for displaying those entries.

    Here’s the basic idea: we use the SQL statement to sort the entries first by date, then by blog ID, and then by time. We use comparison statements with the entry_blog_id field to decide which template to use in dislaying the entry.

    As we loop through the entries, if the first entry from a date is a quicklink, we print a <ul> tag and set a MT variable that a list has been opened. Then if we later encounter a regular weblog entry on that same date or we reach the end of that date range, we print a </ul> and reset the variable. If you don’t care about setting links from one blog apart from the other with a list, box, etc; you can remove the extraneous conditional tags.

  3. So that the include file (combined.txt) will be rebuilt when you add to/edit your other quicklink blog, create a template in that blog with the same information (linked to the same combined.tmpl file).

    Make sure you specify the directory path correctly. For example, if your Quicklink blog is in a subdirectory of your regular weblog (i.e. “/quicklinks”), you may need to use “../combined.txt” (and “../combined.tmpl”) to point the files in the proper direction.

  4. Finally, we include the combined.txt file in your main weblog page. I use the following PHP code:

    <? include("combined.txt"); ?>

    If you don’t have PHP or SHTML, you can try the MTIncludePlus plugin to insert combined.txt into your main weblog page.

7 responses so far (Respond)

Gravatar

Hi Matt,My mainblog’s Id is 1 and the otherone is 10.how can I figure out the mentioned code?I am new and I do not know which numbers I have to change in the code..

Eric Winther | 25 Jan 2004
Gravatar

Just change b=”2″ to b=”10″

Matt | 25 Jan 2004
Gravatar

Integrated Quicklinks Tutorial
Nice tutorial that explains how to integrate a “quicklinks” blog in with your regular weblog entries. Requires a couple of…

ETC. Indulging my inner geek | 10 Jan 2004
Gravatar

Creating an Updates list for Multiple Blogs
I wanted to display a list of new entries in the past n days to my site drawn from multiple blogs, sorted by Date and then Blog, and allowing different formating for entries from different blogs, without directly querying the…

MT Stuff | 15 Jan 2004
Gravatar

Site Changes
It’s probably not all that exciting to you, but I’ve been working on getting all the various RobbyB blog entries onto one page. Matt’s tutorial has been a godsend. To see the potential, check out the beta blog….

RobbyB.com | 20 Jan 2004
Gravatar

Introducing… my plug
Now, I have something new here. I think it is much better (for me) to have stand-alone section where I…

Warnadunia.NET: eXtended | 25 Jul 2004