Skip to content

Tyssen Design — Brisbane Tyssen Design logo

[email protected] (07) 3300 3303

Custom ExpressionEngine template solutions

By /

I've come across a few little solutions/fixes recently to various problems I've encountered when building sites with ExpressionEngine (EE) that I thought it would be worth sharing. A couple of these were tips I picked up from other posters on the EE forums and the third was one I came up with myself to solve a particular problem I had.

Listing entries from all gallery categories on one page

The way this is done is to nest exp:gallery:entries tags inside a exp:gallery:categories tag, using the exp:gallery:categories tag to pass the ID number of the category to the exp:gallery:entries tag. The only problem with this method is that {image_url}, {med_url} and {thumb_url}) don't return a value. To get around this, you can hard-code the path to your gallery images folder and then use the {filename} tag to output the unique name of each image. Using {extension} is also a good idea if you're uploading different file formats but also if you're images are likely to have both upper and lowercase file extensions and you're serving them from a case sensitive OS.

I used the code below to output a list of categories that were children of a parent category which was only used to provide an umbrella heading for the subcategories. Because there were no images actually added to the parent category, the only output from the parent category is its heading with the subcategory then following immediately afterward. The site was also using a Lightbox script to display images, so the link URI points to a larger version of the image rather than a different template.

{exp:gallery:categories gallery="gallery"}
{category_row}
{row}
  <h2>{category}</h2>
  {exp:gallery:entries gallery="gallery" category="{category_id}" orderby="entry_date"}
  <ul class="gallery">
    {entries}
    <li>
    <a href="/images/uploads/gallery/{filename}_medium{extension}" rel="lightbox[services]" <img src="/images/uploads/gallery/{filename}_thumb{extension}" width="{thumb_width}" height="{thumb_height}" alt=""/></a>
    {caption}
    </li>
    {/entries}
  </ul>
  {/exp:gallery:entries}
{/row}
{/category_row}
{subcategory_row}
{row}
  <h3>{category}</h3>
  {exp:gallery:entries gallery="gallery" category="{category_id}" orderby="entry_date"}
  <ul class="gallery">
    {entries}
    <li>
    <a href="/images/uploads/gallery/{filename}_medium{extension}" rel="lightbox[services]" <img src="/images/uploads/gallery/{filename}_thumb{extension}" width="{thumb_width}" height="{thumb_height}" alt=""/></a>
    {caption}
    </li>
    {/entries}
  </ul>
  {/exp:gallery:entries}
{/row}
{/subcategory_row}
{/exp:gallery:categories}

Removing the ?URL= from links in HTML newsletters

Quite a few of the EE sites I've set up make use of the Multiple Newsletters Extension to enable control panel users to compose a newsletter like a normal weblog entry with access to a WYSIWYG editor to format their content nicely. This works very well except that all links in the newsletter come out with ?URL=http:// or ?URL=/ apended to them, which when clicked on, take you to a page that says ‘click the link below’ to be redirected to the page you were trying to reach. Which means the reader of the email has to click twice to get to a linked page or document – not very user-friendly.

The following suggestion is a modification suggested by Michael Byström on the EE forums. You need to edit ext.multiple_newsletters.php and at about line 188 and add:

$newsletter = str_replace("http://www.yourdomain.com/?URL=http%3A%2F%2F", "http://www.yourdomain.com/", $newsletter);
$newsletter = str_replace("http://www.yourdomain.com/?URL=%2F", "http://www.yourdomain.com/", $newsletter);
$newsletter = str_replace("%2F", "/", $newsletter);

The first line removes all ?URL=http and the second removes all ?URL=/ which can occur when linking to files rather than pages on a site. And the last line cleans up and makes sure all / come out as / rather than %2F which will also cause EE to send you to the redirect page rather than to the page you/file you were actually after.

Sub-page navigation for the Structure module

A new module for EE, Structure, was released recently which is like the built-in Pages module, but better because it gives you a visual representation of the site's structure and how pages related to each other, as well as making it easier for control panel users to create new pages and not have to manully type out URIs. The module comes with a built-in function – {exp:structure:nav_sub} – which will show pages at the same level and jumps to a child's level if it has children itself which didn't quite suit a project I was working on because I only wanted to show pages that were children of the page you were currently on and not other pages at the same level. I also needed a way to assign images dynamically to each link. So this is what I came up with:

{exp:weblog:entries weblog="products" disable="categories|member_data|pagination|trackbacks"}
<?php
  global $IN;
  global $DB;
  $entry_array = array();
  $sql="select entry_id from exp_structure where parent_id='{entry_id}'";
  $result = $DB->query($sql);
  if ($result->num_rows > 1) {
    foreach($result->result as $row) {
      $entry_array[]=  $row['entry_id'];
    }
    $entry_ids = implode('|', $entry_array);
  };
?>
{/exp:weblog:entries}
<ul class="yourClass">
{embed="your_template_group/submenu" entryIDs=""}
</ul>

And inside the submenu embed:

{exp:weblog:entries weblog="your_weblog" entry_id="{embed:entryIDs}" dynamic="off" disable="categories|member_data|pagination|trackbacks"}
<li><a href="https://www.tyssendesign.com.au/articles/{url_title}">{title}</a></li>
{/exp:weblog:entries}

Actually, my actual submenu embed example is a bit more complicated than that because I had some conditionals in there to display different formats of menu depending on how many URL segments there were. But the theory is still the same. In your page template, you set the PHP parsing stage (via the template preferences) to output, but set it to input for the submenu embed. The page template passes an array of pages to the submenu embed whose parent_id is the same as the entry_id of the current page. Once you have that list of IDs, you can do whatever you like with them in the submenu embed which means you can present them as just links on one page, and maybe with images and descriptions on another page etc.

These three are fairly specific pieces of functionality, but hopefully someone may find them useful in a project they're working on.

Like to say hello? Give us a call on (07) 3300 3303, send us an email to enquiries@tyssendesign.com.au, or a message by filling in the form below.