Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

EE: selected items module to build nav for certain url segment

// can be used to place custom menus made with 'selected items' module

{if segment_1 == "westergozone"}
<ul>
{exp:selecteditems name="westergo_paginas"}
{exp:weblog:entries weblog="westergo_paginas" fixed_order="{selecteditems_id}"}
<li class="{switch="one|two|three"}">{count}. <a href="{path=home}{url_title}">{menu-title}</a></li>
{/exp:weblog:entries}
{/exp:selecteditems}
</ul>
{/if}

expression engine: page with category text and then category links

// Purpose: page with category header and text and category links

{exp:weblog:category_heading weblog="pages"}
			  <h1>{category_name}</h1>
		    	<p>{category_intro}</p>
				<p>{category_body}</p>
			{/exp:weblog:category_heading}
			{!-- Only show header if this category is not the bottom level --}
            {if {is_bottom} == 0}
			  <h2>Onderwerpen:</h2>
			{/if}
			<ul>
            {exp:child_categories 
			  parent="{show_cat_id}" 
			  child_categories_sort_by="custom" 
		      show_empty="yes" 
			  invalid_input="silence"
			}
			  {child_category_start}
                <li><a href="{path="main/index"}section/{child_category_url_title}">{child_category_name}</a></li>
              {child_category_end}
            {/exp:child_categories}
			</ul>
            {exp:weblog:entries 
              weblog="pages"
			  	disable="member_data|pagination|trackbacks"
				rdf="off"
            }
	          {if total_results > 1}
			    {if count == 1}
			      <h2>Lees verder:</h2>
			      <ul>
			    {/if}
			    <li><a href="{url_title_path="articles/index"}section/{categories limit="1"}{category_url_title}/{/categories}">{title}</a></li>	
			    {if count == total_results}
			      </ul>
			    {/if}
              {if:else}
			    {pages_image}<img src="{file_thumb_url}" align="right" class="image" hspace="0" />{/pages_image}
			    {pages_body}
		      {/if}
		    {/exp:weblog:entries}
			<div id="back_button">
				<a href="javascript:history.go(-1)"><< terug</a>
			</div>

expression engine: overview of links and downloads in categories

// Purpose: make overview page of links and downloads in certain categories

<h1>Links & Downloads</h1>
			{!-- the links in their categories  --}
			<h2>Links</h2>
		 	{exp:weblog:categories 
			  weblog="links" 
			  style="linear" 
			  show_empty="no"
			}
			<h3>{category_name}</h3>
			{exp:weblog:entries 
			  weblog="links" 
			  orderby="title"
			  sort="asc"
			  category="{category_id}"
			  rdf="off"
			  disable="member_data|pagination|trackbacks"
			  dynamic="off"
			}
        	   <a href="{links_link}" target="_blank">{links_description}</a><br />
    		{/exp:weblog:entries}
			{/exp:weblog:categories} 
			{!-- end of the links and their cats --}
			{!-- the downloads and their categories --}
			<br />
			<h2>Downloads</h2>
			{exp:weblog:categories 
			  weblog="downloads" 
			  style="linear" 
			  show_empty="no"
			}
			<h3>{category_name}</h3>
			{exp:weblog:entries 
			  weblog="downloads" 
			  orderby="title" 
			  sort="asc"
			  category="{category_id}"
			  rdf="off"
			  disable="member_data|pagination|trackbacks"
			  dynamic="off"
			}
              <a href="{downloads_file}" target="_blank">{downloads_description}</a><br />
    		{/exp:weblog:entries}
			{/exp:weblog:categories} 
			{!-- end of the downloads and their categories --}

expression engine: plugin "pi.child_categories.php"

// Purpose: Find category id. Use found category id as parameter of other tags.

<?php

/*
=====================================================
 This ExpressionEngine plugin was created by Laisvunas Sopauskas
 - laisvunas@classicsunlocked.net
 - http://www.classicsunlocked.net/
=====================================================
 This program is freeware; 
 you may use this code for any purpose, commercial or
 private, without any further permission from the author.
=====================================================
 File: pi.child_categories.php
-----------------------------------------------------
 Purpose: Find all child categories after specifying parent or 
 sibling category. Display lists of entries posted to child
 categories. 
=====================================================
*/

$plugin_info = array(
						'pi_name'			=> 'Child Categories',
						'pi_version'		=> '1.4.1',
						'pi_author'			=> 'Laisvunas Sopauskas',
						'pi_author_url'		=> 'http://www.classicsunlocked.net/',
						'pi_description'	=> 'Allows you to find all child categories after specifying parent or 
 sibling category and display lists of entries posted to child categories.',
						'pi_usage'			=> child_categories::usage()
					);
					
class Child_categories {
  
  var $return_data = '';
  
  function Child_categories()
  {
    global $TMPL, $DB;
    
    // Fetch the tagdata
		  $tagdata = $TMPL->tagdata;
		  
    // Define variables
    $siteclause = '';
    $weblogclause = '';
    $sortorderclause_categories = '';
    $sortorderclause_entries = '';
    $limitclause = '';
    $parent_cat_name = '';
    $parent_cat_url_title = '';
    $child_category_id = '';
    $entries_total = '';
    $child_category_name = '';
    $child_category_url_title = '';
    $child_category_order_num = '';
    $weblog_name = '';
    $weblog_url = '';
    $title = '';
    $url_title = '';
    $entry_date = '';
    $tagdatanew = '';
    $parentdatanew = '';
    $childdatanew = '';
    $entriesdatanew = '';
    $parentdataexists = '';
    $childdataexists = '';
    $entriesdataexists = '';
    $entrieswrappertop_dataexists = '';
    $entrieswrapperbottom_dataexists = '';
    $entrieswrappertop_data = '';
    $entrieswrapperbottom_data = '';
    $found_invalid = FALSE;
    $parentarray = array();
		  
		  // Fetch params
    $parent = $TMPL->fetch_param('parent');
    $sibling = $TMPL->fetch_param('sibling');
    $site = $TMPL->fetch_param('site');
    $child_categories_sort_by = $TMPL->fetch_param('child_categories_sort_by');
    $child_categories_sort_direction = $TMPL->fetch_param('child_categories_sort_direction');
    $show_empty = $TMPL->fetch_param('show_empty');
    $entries_sort_by = $TMPL->fetch_param('entries_sort_by');
    $entries_sort_direction = $TMPL->fetch_param('entries_sort_direction');
    $entries_limit = $TMPL->fetch_param('entries_limit');
    $date_format = $TMPL->fetch_param('date_format');
    $weblog = $TMPL->fetch_param('weblog');
    $invalid_input = $TMPL->fetch_param('invalid_input');
    
    // At least one out of "parent" and "sibling" parameters must be defined
    if ($parent === FALSE AND $sibling === FALSE)
    {
      if ($invalid_input === 'alert')
      {
        exit('Error! At least one out of "parent" and "sibling" parameters of exp:child_categories tag must be defined.');
      }
      $found_invalid = TRUE;
    }
    
    // Parameter "child_categories_sort_by" accepts only "name", "id" or "custom" as its value
    if ($child_categories_sort_by !== FALSE AND $child_categories_sort_by !== 'name' AND $child_categories_sort_by !== 'id' AND $child_categories_sort_by !== 'custom')
    {
      if ($invalid_input === 'alert')
      {
        exit('Error! Parameter "child_categories_sort_by" of exp:child_categories tag accepts only "name", "id" or "custom" as its value.');
      }
      $found_invalid = TRUE;
    }
    
    // Parameter "child_categories_sort_direction" accepts only "asc" or "desc" as its value
    if ($child_categories_sort_direction !== FALSE AND $child_categories_sort_direction !== 'asc' AND $child_categories_sort_direction !== 'desc')
    {
      if ($invalid_input === 'alert')
      {
        exit('Error! Parameter "child_categories_sort_direction" of exp:child_categories tag accepts only "asc" or "desc" as its value.');
      }
      $found_invalid = TRUE;
    }
    
    // Parameter "show_empty" accepts only "yes" or "no" as its value
    if ($show_empty !== FALSE AND $show_empty !== 'yes' AND $show_empty !== 'no')
    {
      if ($invalid_input === 'alert')
      {
        exit('Error! Parameter "show_empty" of exp:child_categories tag accepts only "yes" or "no" as its value.');
      }
      $found_invalid = TRUE;
    }
    
    // Parameter "entries_sort_by" accepts only "date" or "title" as its value
    if ($entries_sort_by !== FALSE AND $entries_sort_by !== 'date' AND $entries_sort_by !== 'title')
    {
      if ($invalid_input === 'alert')
      {
        exit('Error! Parameter "entries_sort_by" of exp:child_categories tag accepts only "date" or "title" as its value.');
      }
      $found_invalid = TRUE;
    }
    
    // Parameter "entries_sort_direction" accepts only "asc" or "desc" as its value
    if ($entries_sort_direction !== FALSE AND $entries_sort_direction !== 'asc' AND $entries_sort_direction !== 'desc')
    {
      if ($invalid_input === 'alert')
      {
        exit('Error! Parameter "entries_sort_direction" of exp:child_categories tag accepts only "asc" or "desc" as its value.');
      }
      $found_invalid = TRUE;
    }
    
    if ($found_invalid === FALSE)
    {
      // Form weblog clause
      if($weblog !== FALSE)
      {
        // Clean whitespace from "weblog" parameter value
        $weblog = str_replace(' ', '', $weblog);
        // Check if "weblog" param contains "not"
        if (strpos($weblog, 'not')===0)
        {
          // In case "weblog" param contains "not" form SQL clause using "AND" and "!=" operators
          $weblog = substr($weblog, 3);
          $weblog_shortnames_array = explode('|', $weblog);
          foreach($weblog_shortnames_array as $shortname)
          {
            $weblogclause .= " AND exp_weblogs.blog_name!='".$shortname."' ";
          }
        }
        else
        {
          // In case "weblog" param does not contain "not" form SQL clause using "OR" and "=" operators
          $weblog_shortnames_array = explode('|', $weblog);
          if (count($weblog_shortnames_array)==1)
          {
            $weblogclause = " AND exp_weblogs.blog_name='".$weblog_shortnames_array[0]."' ";
          }
          else
          {
            foreach($weblog_shortnames_array as $shortname)
            {
              $weblogclause .= " OR exp_weblogs.blog_name='".$shortname."' ";
            }
            $weblogclause = substr($weblogclause, 4);
            $weblogclause = " AND (".$weblogclause.")";
          }
        }
      }
      //echo $weblogclause.'<br>';
      
      // Form site clause
      if ($site !== FALSE)
      {
        $siteclause = " AND exp_categories.site_id='".$site."' ";
        //echo $siteclause.'<br>';
      }
      
      // Form child categories sort order clause
      if ($child_categories_sort_by === FALSE OR $child_categories_sort_by === 'name')
      {
        $sortorderclause_categories = ' ORDER BY cat_name ';
      }
      elseif ($child_categories_sort_by === 'id')
      {
        $sortorderclause_categories = ' ORDER BY cat_id ';
      }
      elseif ($child_categories_sort_by === 'custom')
      {
        $sortorderclause_categories = ' ORDER BY cat_order ';
      }
      if ($child_categories_sort_direction === FALSE OR $child_categories_sort_direction === 'asc')
      {
        $sortorderclause_categories .= ' ASC ';
      }
      elseif ($child_categories_sort_direction === 'desc')
      {
        $sortorderclause_categories .= ' DESC ';
      }
      //echo $sortorderclause_categories.'<br>';
      
      // Supply default value for child categories show_empty parameter
      if ($show_empty === FALSE)
      {
        $show_empty ='no';
      }
      
      // Form entries sort order clause
      if ($entries_sort_by === FALSE OR $entries_sort_by === 'date')
      {
        $sortorderclause_entries = ' ORDER BY exp_weblog_titles.entry_date ';
      }
      elseif ($entries_sort_by === 'title')
      {
        $sortorderclause_entries = ' ORDER BY exp_weblog_titles.title ';
      }
      if ($entries_sort_direction === FALSE OR $entries_sort_direction === 'desc')
      {
        $sortorderclause_entries .= ' DESC ';
      }
      elseif ($entries_sort_direction === 'asc')
      {
        $sortorderclause_entries .= ' ASC ';
      }
      //echo $sortorderclause_entries.'<br>';
      
      // Form entries limit clause
      if ($entries_limit === FALSE)
      {
        $limitclause = ' LIMIT 0, 10';
      }
      elseif ($entries_limit === 'none')
      {
        $limitclause = '';
      }
      else
      {
        $limitclause = ' LIMIT 0, '.$entries_limit;
      }
      //echo $limitclause.'<br>';
      
      // Form default date format string
      if ($date_format === FALSE)
      {
        $date_format = 'Y-m-d';
      }
      
      // I. Finding data enclosed between {parent_category_start} and {parent_category_end}, 
      // {child_category_start} and {child_category_end},
      // {entries_start} and {entries_end},
      // {entries_wrapper_top_start} and {entries_wrapper_top_end},
      // {entries_wrapper_bottom_start} and {entries_wrapper_bottom_end} tag pairs
      
      // Find if there are tags {parent_category_start} and {parent_category_end}
      $closingtagpos = strpos($tagdata, '{parent_category_end}');
      //echo $closingtagpos.'<br>';
      $openingtagpos = strpos($tagdata, '{parent_category_start}');
      //echo $openingtagpos.'<br>';
      
      // In case there are tags {parent_category_start} and {parent_category_end}
      // find data enclosed between them
      if ($closingtagpos !== FALSE AND $openingtagpos !== FALSE)
      {
        $parentdataexists = TRUE;
        $parentdata = substr($tagdata, 0, $closingtagpos);
        $openingtagpos += 23;
        $parentdata = substr($parentdata, $openingtagpos);
        //echo $parentdata.'<br>'; 
      }
      
      // Find if there are tags {child_category_start} and {child_category_end}
      $closingtagpos = strpos($tagdata, '{child_category_end}');
      //echo $closingtagpos.'<br>';
      $openingtagpos = strpos($tagdata, '{child_category_start}');
      //echo $openingtagpos.'<br>';
      
      // In case there are tags {child_category_start} and {child_category_end}
      // find data enclosed between them
      if ($closingtagpos !== FALSE AND $openingtagpos !== FALSE)
      {
        $childdataexists = TRUE;
        $childdata = substr($tagdata, 0, $closingtagpos);
        $openingtagpos += 22;
        $childdata = substr($childdata, $openingtagpos);
        //echo $childdata.'<br>';  
      }
      
      // Find if there are tags {entries_start} and {entries_end}
      $closingtagpos = strpos($tagdata, '{entries_end}');
      //echo $closingtagpos.'<br>';
      $openingtagpos = strpos($tagdata, '{entries_start}');
      //echo $openingtagpos.'<br>';
      
      // In case there are tags {entries_start} and {entries_end}
      // find data enclosed between them
      if ($closingtagpos !== FALSE AND $openingtagpos !== FALSE)
      {
        $entriesdataexists = TRUE;
        $entriesdata = substr($tagdata, 0, $closingtagpos);
        $openingtagpos += 15;
        $entriesdata = substr($entriesdata, $openingtagpos);
        //echo $entriesdata.'<br>';
      }
      
      // Find if there are tags {entries_wrapper_top_start} and {entries_wrapper_top_end}
      $closingtagpos = strpos($tagdata, '{entries_wrapper_top_end}');
      //echo $closingtagpos.'<br>';
      $openingtagpos = strpos($tagdata, '{entries_wrapper_top_start}');
      //echo $openingtagpos.'<br>';
      
      // In case there are tags {entries_wrapper_top_start} and {entries_wrapper_top_end}
      // find data enclosed between them
      if ($closingtagpos !== FALSE AND $openingtagpos !== FALSE)
      {
        $entrieswrappertop_dataexists = TRUE;
        $entrieswrappertop_data = substr($tagdata, 0, $closingtagpos);
        //echo $entrieswrappertop_data.'<br>';
        $openingtagpos += 27;
        $entrieswrappertop_data = substr($entrieswrappertop_data, $openingtagpos);
        //echo $entrieswrappertop_data.'<br>';
      }
      
      // Find if there are tags {entries_wrapper_bottom_start} and {entries_wrapper_top_end}
      $closingtagpos = strpos($tagdata, '{entries_wrapper_bottom_end}');
      //echo $closingtagpos.'<br>';
      $openingtagpos = strpos($tagdata, '{entries_wrapper_bottom_start}');
      //echo $openingtagpos.'<br>';
      
      // In case there are tags {entries_wrapper_bottom_start} and {entries_wrapper_bottom_end}
      // find data enclosed between them
      if ($closingtagpos !== FALSE AND $openingtagpos !== FALSE)
      {
        $entrieswrapperbottom_dataexists = TRUE;
        $entrieswrapperbottom_data = substr($tagdata, 0, $closingtagpos);
        //echo $entrieswrapperbottom_data.'<br>';
        $openingtagpos += 30;
        $entrieswrapperbottom_data = substr($entrieswrapperbottom_data, $openingtagpos);
        //echo $entrieswrapperbottom_data.'<br>';
      }
      
      // II. Dealing with parent category
      
      // In case "sibling" parameter is defined find parent category id
      if ($sibling !== FALSE)
      {
        // Create SQL query string to find parent category id
        $todoinit = "SELECT parent_id FROM exp_categories WHERE exp_categories.cat_id='".$sibling."' ".$siteclause." LIMIT 0, 1";
        //echo $todoinit.'<br>';
        
        // Perform SQL query
        $queryinit = $DB->query($todoinit);
        //echo $queryinit->num_rows.'<br>';
        
        // Find parent category id
        if ($queryinit->num_rows === 1)
        {
          $parent = $queryinit->row['parent_id'];
          //echo $parent.'<br>';
          
          // Place parent category id into ids array
          $parentarray[0] = $parent;
          //echo $parentarray[0].'<br>';
        }
      }
      
      // In case "sibling" parameter is not defined check if "parent" parameter provides
      // one or more parent category ids
      if ($sibling === FALSE)
      {
        // Clean whitespace from "parent" parameter value
        $parent = str_replace(' ', '', $parent);
        // Split value of "parent" parameter using "|" symbol as separator
        $parentarray = explode('|', $parent);
        //echo $parentarray[0].'<br>';
        //echo $parentarray[1].'<br>';
      }
      
      if (count($parentarray) > 0)
      {
      
        foreach($parentarray as $member)
        {
          $parent = $member;
          
          // Create SQL query string to find parent category name, parent category url_title, parent category description, parent category image
          $todoinit2 = "SELECT cat_name, cat_url_title, cat_description, cat_image FROM exp_categories WHERE exp_categories.cat_id='".$parent."' ".$siteclause." LIMIT 0, 1";
          //echo $todoinit2.'<br>';
          
          // Perform SQL query
          $queryinit2 = $DB->query($todoinit2);
          //echo $queryinit2->num_rows.'<br>';
          
          // Find parent category name, parent category url_title, parent category description, parent category image
          if ($queryinit2->num_rows === 1)
          {
            $parent_cat_name = $queryinit2->row['cat_name'];
            $parent_cat_url_title = $queryinit2->row['cat_url_title'];
            $parent_cat_description = $queryinit2->row['cat_description'];
            $parent_cat_image = $queryinit2->row['cat_image'];
            //echo $parent_cat_name.' '.$parent_cat_url_title.' '..'<br>';
          }
          
          // If there are {parent_category_start}, {parent_category_end} tags, then
          // manipulate data enclosed between them
          if ($parentdataexists === TRUE)
          {
            $parentdatanew = $parentdata;
            $parentdatanew = str_replace('{parent_category_id}', $parent, $parentdatanew);
            $parentdatanew = str_replace('{parent_category_name}', $parent_cat_name, $parentdatanew);
            $parentdatanew = str_replace('{parent_category_url_title}', $parent_cat_url_title, $parentdatanew);
            $parentdatanew = str_replace('{parent_category_description}', $parent_cat_description, $parentdatanew);
            $parentdatanew = str_replace('{parent_category_image}', $parent_cat_image, $parentdatanew);
            //echo $parentdatanew.'<br>';
            $tagdatanew .= $parentdatanew;
          }
        
          // III. Dealing with child categories
        
          // Create SQL query string to find child categories ids, names, url_titles, descriptions, images
          $todo = "SELECT cat_id, cat_name, cat_url_title, cat_description, cat_image, cat_order FROM exp_categories WHERE exp_categories.parent_id='".$parent."' ".$siteclause.$sortorderclause_categories;
          //echo $todo.'<br>';
          
          // Perform SQL query
          $query = $DB->query($todo);
          
          foreach ($query->result as $onerow)
          {
            // Find child category id, name, url_title
            $child_category_id = $onerow['cat_id'];
            $child_category_name = $onerow['cat_name'];
            $child_category_url_title = $onerow['cat_url_title'];
            $child_category_description = $onerow['cat_description'];
            $child_category_image = $onerow['cat_image'];
            $child_category_order_num = $onerow['cat_order'];
            //echo $child_category_order_num.' '.$child_category_id.' '.$child_category_name.' '.$child_category_url_title.'<br>';
            
            // Create SQL query string to find total number of entries posted into child category
            $todonext = "SELECT exp_weblog_titles.url_title, exp_weblog_titles.title, exp_weblog_titles.entry_date, exp_weblog_titles.site_id, exp_weblogs.blog_name, exp_weblogs.blog_title, exp_weblogs.blog_url, exp_categories.cat_name, exp_categories.cat_id, exp_categories.cat_url_title  FROM exp_category_posts, exp_weblog_titles, exp_weblogs, exp_categories WHERE exp_category_posts.entry_id=exp_weblog_titles.entry_id AND exp_weblog_titles.weblog_id=exp_weblogs.weblog_id AND exp_category_posts.cat_id=exp_categories.cat_id AND exp_weblog_titles.site_id=exp_categories.site_id AND exp_category_posts.cat_id='".$child_category_id."' ".$weblogclause.$siteclause.$sortorderclause_entries;
            //echo $todonext.'<br>';        
            
            // Perform SQL queries
            $querynext = $DB->query($todonext);
            
            // Find total number of entries posted into child category
            $entries_total = $querynext->num_rows;
            //echo $entries_total.'<br>';
            
            // In case "show_empty" parameter has the value "no" and total number of entries posted into child category is 0 do not display such category 
            if ($entries_total > 0 OR $show_empty === 'yes')
            {
            
              // If there are tags {child_category_start} and {child_category_end}
              // manipulate data enclosed between them
              if ($childdataexists === TRUE)
              {
                $childdatanew = $childdata;
                $childdatanew = str_replace('{parent_category_id}', $parent, $childdatanew);
                $childdatanew = str_replace('{parent_category_name}', $parent_cat_name, $childdatanew);
                $childdatanew = str_replace('{parent_category_description}', $parent_cat_description, $childdatanew);
                $childdatanew = str_replace('{parent_category_image}', $parent_cat_image, $childdatanew);
                $childdatanew = str_replace('{parent_category_url_title}', $parent_cat_url_title, $childdatanew);
                $childdatanew = str_replace('{child_category_id}', $child_category_id, $childdatanew);
                $childdatanew = str_replace('{child_category_name}', $child_category_name, $childdatanew);
                $childdatanew = str_replace('{child_category_url_title}', $child_category_url_title, $childdatanew);
                $childdatanew = str_replace('{child_category_description}', $child_category_description, $childdatanew);
                $childdatanew = str_replace('{child_category_image}', $child_category_image, $childdatanew);
                $childdatanew = str_replace('{child_category_order_num}', $child_category_order_num, $childdatanew);
                $childdatanew = str_replace('{entries_total}', $entries_total, $childdatanew);
                $tagdatanew .= $childdatanew;
                if ($entriesdataexists === TRUE AND $entries_total > 0 AND $entrieswrappertop_dataexists === TRUE AND $entrieswrapperbottom_dataexists === TRUE)
                {
                  $tagdatanew .= $entrieswrappertop_data;
                }
              }
              
              // IV. Dealing with titles posted into child categories
              
              // Create SQL query string to find weblog_name, weblog_url, titles, 
              // url_titles and dates of entries posted into child category
              $todolast = $todonext.$limitclause;
              //echo $todolast.'<br>';
              
              // Perform SQL query
              $querylast = $DB->query($todolast);
              
              // Reset incrementer
              $incrementer = 1;
              
              // If there are tagpair {entries_start}{entries_end}, then,
              // first, for every title posted into child category find its
              // weblog name
              // weblog url
              // title
              // url title
              // entry date 
              // manipulate data enclosed between them
              // second, manipulate data enclosed between that tagpair
              if ($entriesdataexists === TRUE)
              {
                foreach ($querylast->result as $rowlast)
                {
                  $weblog_short_name = $rowlast['blog_name'];
                  $weblog_name = $rowlast['blog_title'];
                  $weblog_url = $rowlast['blog_url'];
                  $title = $rowlast['title'];
                  $url_title = $rowlast['url_title'];
                  $entry_date = date($date_format, $rowlast['entry_date']);
                  //echo $weblog_name.' '.$weblog_url.' '.$title.' '.$url_title.' '.$entry_date.'<br>';
                  $entriesdatanew = $entriesdata;
                  $entriesdatanew = str_replace('{parent_category_id}', $parent, $entriesdatanew);
                  $entriesdatanew = str_replace('{parent_category_name}', $parent_cat_name, $entriesdatanew);
                  $entriesdatanew = str_replace('{parent_category_description}', $parent_cat_description, $entriesdatanew);
                  $entriesdatanew = str_replace('{parent_category_image}', $parent_cat_image, $entriesdatanew);
                  $entriesdatanew = str_replace('{parent_category_url_title}', $parent_cat_url_title, $entriesdatanew);
                  $entriesdatanew = str_replace('{child_category_id}', $child_category_id, $entriesdatanew);
                  $entriesdatanew = str_replace('{child_category_name}', $child_category_name, $entriesdatanew);
                  $entriesdatanew = str_replace('{child_category_url_title}', $child_category_url_title, $entriesdatanew);
                  $entriesdatanew = str_replace('{child_category_description}', $child_category_description, $entriesdatanew);
                  $entriesdatanew = str_replace('{child_category_image}', $child_category_image, $entriesdatanew);
                  $entriesdatanew = str_replace('{child_category_order_num}', $child_category_order_num, $entriesdatanew);
                  $entriesdatanew = str_replace('{entries_total}', $entries_total, $entriesdatanew);
                  $entriesdatanew = str_replace('{weblog_short_name}', $weblog_short_name, $entriesdatanew);
                  $entriesdatanew = str_replace('{weblog_name}', $weblog_name, $entriesdatanew);
                  $entriesdatanew = str_replace('{weblog_url}', $weblog_url, $entriesdatanew);
                  $entriesdatanew = str_replace('{title}', $title, $entriesdatanew);
                  $entriesdatanew = str_replace('{url_title}', $url_title, $entriesdatanew);
                  $entriesdatanew = str_replace('{entry_date}', $entry_date, $entriesdatanew);
                  $entriesdatanew = str_replace('{count}', $incrementer, $entriesdatanew);
                  $tagdatanew .= $entriesdatanew;
                  
                  if (($incrementer === $entries_total OR $incrementer == $entries_limit) AND $entrieswrappertop_dataexists === TRUE AND $entrieswrapperbottom_dataexists === TRUE)
                  {
                    $tagdatanew .= $entrieswrapperbottom_data;
                  }
                  //$tagdatanew .= '<br> incrementer: '.$incrementer.' entries_total: '.$entries_total.' entries_limit: '.$entries_limit.' entrieswrapperbottom_data: '.$entrieswrapperbottom_data.'<br>';
                  $incrementer++;
                }
              }
            }
          }
          //echo $tagdatanew.'<br>';
          
          // Output transformed tagdata
          $this->return_data = $tagdatanew;
        }
      }
    }
  }
  // END FUNCTION
  
  // ----------------------------------------
  //  Plugin Usage
  // ----------------------------------------
  // This function describes how the plugin is used.
  //  Make sure and use output buffering
  
  function usage()
  {
  ob_start(); 
  ?>
  
  PARAMETERS:

  1) parent - Optional. Allows you to specify parent category id number 
  (the id number of each category is displayed in the Control Panel).
  You can stack parent categories using pipe character e.g. parent="3|16|28".
  
  2) sibling - Optional. Allows you to specify child category id number 
  (the id number of each category is displayed in the Control Panel).
  
  Either "parent" or "sibling" parameter MUST BE defined. 
  
  3) site - Optional. Allows you to specify site id number.
  
  4) child_categories_sort_by - Optional. Allows you to specify sort order
  of child categories. This parameter accepts three values: "name" (child
  categories will be sorted by name), "id" (child categories will be sorted 
  by id number), and "custom" (child categories will be sorted using custom order 
  as defined in control panel). Default value is "name".
  
  5) child_categories_sort_direction - Optional. Allows you to specify sort direction
  of child categories. This parameter accepts two values: "asc" and "desc".
  Default value is "asc".
  
  6) show_empty - Optional. Allows you to specify if child categories having no
  entries should be displayed or not. This parameter accepts two values: "yes" and "no".
  Default value is "no".
  
  7) entries_sort_by - Optional. Allows you to specify sort order of entries.
  This parameter accepts two values: "title" and "date". Default value is "date".
  
  8) entries_sort_direction - Optional. Allows you to specify sort direction
  of entries. This parameter accepts two values: "asc" and "desc".
  Default value is "desc".
  
  9) entries_limit - Optional. Allows you to specify how many entries posted into 
  child category should be displayed. This parameter accepts as its value an integer
  or "none". Default value is "10". Value "none" means that all entries will be
  displayed.
  
  10) date_format - Optional. Allows you to specify PHP date format string
  (Not ExpressionEngine's date format string!). Default value is "Y-m-d".
  
  11) invalid_input - Optional. Accepts two values: “alert” and “silence”.
  Default value is “silence”. If the value is “alert”, then in cases when some
  parameter’s value is invalid plugin exits and PHP alert is being shown;
  if the value is “silence”, then in cases when some parameter’s value
  is invalid plugin finishes its work without any alert being shown. 
  Set this parameter to “alert” for development, and to “silence” - for deployment.
  
  VARIABLE PAIRS:
  
  1) {parent_category_start}{parent_category_end} - Allows you to specify portion of
  code which will be iterated as many times as there are parent categories.
  Single variables available for use inside this variable pair:
  {parent_category_id}
  {parent_category_name}
  {parent_category_url_title}
  {parent_category_description}
  {parent_category_image}
  
  2) {child_category_start}{child_category_end} - Allows you to specify portion of
  code which will be iterated as many times as there are child categories.
  Single variables available for use inside this variable pair:
  {parent_category_id}
  {parent_category_name}
  {parent_category_url_title}
  {parent_category_description}
  {parent_category_image}
  {child_category_id}
  {child_category_name}
  {child_category_url_title}
  {child_category_description}
  {child_category_image}
  {child_category_order_num}
  {entries_total}
  
  3) {entries_start}{entries_end} - Allows you to specify portion of
  code which will be iterated as many times as there are entries posted into child
  category. Single variables available for use inside this variable pair:
  {parent_category_id}
  {parent_category_name}
  {parent_category_url_title}
  {parent_category_description}
  {parent_category_image}
  {child_category_id}
  {child_category_name}
  {child_category_url_title}
  {child_category_description}
  {child_category_image}
  {child_category_order_num}
  {entries_total}
  {weblog_name}
  {weblog_short_name}
  {weblog_url}
  {title}
  {url_title}
  {entry_date}
  {count}
  
  4) {entries_wrapper_top_start}{entries_wrapper_top_end} - Allows you to specify top part of
  the code with which you want to wrap output of {entries_start}{entries_end} variable pair.
  
  5) {entries_wrapper_bottom_start}{entries_wrapper_bottom_end} - Allows you to specify bottom part of
  the code with which you want to wrap output of {entries_start}{entries_end} variable pair.
  
  The tag {exp:child_categories} MUST contain at least one variable pair  out of 
  {parent_category_start}{parent_category_end}, {child_category_start}{child_category_end} and
  {entries_start}{entries_end} variable pairs and each single variable MUST BE inside 
  relevant variable pair.
 
  SINGLE VARIABLES:
  
  1) {parent_category_id} - outputs id number of parent category.
  
  2) {parent_category_name} - outputs name of parent category.
  
  3) {parent_category_url_title} - outputs url title of parent category.
  
  4) {parent_category_description} - outputs description title of parent category.
  
  5) {parent_category_image} - outputs url of the image of parent category.
  
  6) {child_category_id} - outputs id number of child category.
  
  7) {child_category_name} - outputs name of child category.
  
  8) {child_category_url_title} - outputs url title of child category.
  
  9) {child_category_description} - outputs description title of child category.
  
  10) {child_category_image} - outputs url of the image of child category.
  
  11) {child_category_order_num} - outputs number used for custom ordering of
  categories.
  
  12) {entries_total} - outputs total number of entries posted into child category.
  
  13) {weblog_name} - outputs full weblog name into which entry is posted.
  
  14) {weblog_short_name} - outputs short weblog name into which entry is posted.
  
  15) {weblog_url} - outputs weblog url as specified in control panel.
  
  16) {title} - outputs title of entry.
  
  17) {url_title} - outputs url title of entry.
  
  18) {entry_date} - outputs entry date of entry.
  
  19) {count} - outputs order number of entry.
  
  EXAMPLE OF USAGE:
  
  {exp:child_categories parent="18|29" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes" entries_sort_by="date" entries_sort_direction="asc" entries_limit="3" site="1"}
  {parent_category_start}
  <h1><a href="{homepage}/category/{parent_category_url_title}/">{parent_category_name}</a></h1>
  {parent_category_end}
  {child_category_start}
  <h2><a href="{homepage}/category/{child_category_url_title}/">{child_category_name}</a></h2>
  Total entries: {entries_total}<br>
  {child_category_end}
  {entries_wrapper_top_start}< div style="border: 1px solid red;" >{entries_wrapper_top_end}
  {entries_start}
  <a href="{weblog_url}{url_title}">{title}</a> Weblog: {weblog_name}, posted: {entry_date}<br>
  {entries_end}
  {entries_wrapper_bottom_start}< /div >{entries_wrapper_bottom_end}
  {/exp:child_categories}
  
  This code will output:
  
  Parent category 18
    Child category
    Total entries
       Entry
       Entry
       Entry
    Child category
    Total entries
       Entry
       Entry
       Entry
    Child category
    Total entries
       Entry
       Entry
       Entry
  Parent category 29
    Child category
    Total entries
       Entry
       Entry
       Entry
    Child category
    Total entries
       Entry
       Entry
       Entry

  Place the tag {exp:child_categories} in any of your templates.
  
  <?php
  $buffer = ob_get_contents();
  	
  ob_end_clean(); 
  
  return $buffer;
  }
  // END USAGE

}
// END CLASS
?>

expression engine: plugin "pi.category_id.php"

// Purpose: Find category id. Use found category id as parameter of other tags.

<?php

/*
=====================================================
 This ExpressionEngine plugin was created by Laisvunas Sopauskas
 - laisvunas@classicsunlocked.net
 - http://www.classicsunlocked.net/
=====================================================
 This program is freeware; 
 you may use this code for any purpose, commercial or
 private, without any further permission from the author.
=====================================================
 File: pi.category_id.php
-----------------------------------------------------
 Purpose: Find category id. Use found category id as parameter of other tags.
=====================================================
*/

$plugin_info = array(
						'pi_name'			=> 'Category Id',
						'pi_version'		=> '1.3',
						'pi_author'			=> 'Laisvunas Sopauskas',
						'pi_author_url'		=> 'http://www.classicsunlocked.net/',
						'pi_description'	=> 'Allows you to find category id. Use found category id as parameter of other tags.',
						'pi_usage'			=> category_id::usage()

					);

class Category_id {

  var $return_data="";
  
  function Category_id()
  {
    global $IN, $TMPL, $DB;
    
    // Fetch the tagdata
		  $tagdata = $TMPL->tagdata;
    
    // Fetch params
    $groupid = $TMPL->fetch_param('category_group');
    $caturltitle = $TMPL->fetch_param('category_url_title');
    $onfailure = $TMPL->fetch_param('on_failure');
    $invalid_input = $TMPL->fetch_param('invalid_input');
    
    // Define variable
    $found_invalid = FALSE;
    
    // category_group and category_url_title params must be defined
    if ($groupid === FALSE)
    {
      if ($invalid_input === 'alert')
      {
        exit('Error! Parameter "category_group" of exp:category_id tag not defined.');      
      }
      $found_invalid = TRUE;
    }
    elseif ($caturltitle === FALSE)
    {
      if ($invalid_input === 'alert')
      {
      exit('Error! Parameter "category_url_title" of exp:category_id tag not defined.');     
      }
      $found_invalid = TRUE;
    }
    
    // Simple validation of params values
    $invalidchars = array('~', '#', '*', '{', '}', '[', ']', '/', '\\', '<', '>', '\'', '\"', ' ', '|', ':');
    foreach($invalidchars as $char)
    {
      if (strpos($groupid,$char) > 0 OR strpos($groupid,$char) === 0) 
      {
        if ($invalid_input === 'alert')
        {
          exit('Error! Parameter "category_group" of exp:category_id tag contains illegal character.');       
        }
        $found_invalid = TRUE;
      }
    }
    foreach($invalidchars as $char)
    {
      if (strpos($caturltitle,$char) > 0 OR strpos($caturltitle,$char) === 0) 
      {
        if ($invalid_input === 'alert')
        {
          exit('Error! Parameter "category_url_title" of exp:category_id tag contains illegal character.');       
        }
        $found_invalid = TRUE;
      }
    }
    
    if ($found_invalid === FALSE)
    {
      // Create SQL query string
      $todo = "SELECT cat_id FROM exp_categories WHERE group_id = '".$groupid."' AND cat_url_title = '".$caturltitle."'";
      
      // Perform SQL query
      $query = $DB->query($todo);
      
      // Form result string
      $resultstring = '';
      foreach($query->result as $row)
      {
        $resultstring .= $row['cat_id'];
      }
      
      // If on_failure param was defined and needed category id was not found 
      // then on_failure param value will be our resultstring
      if ($onfailure !== FALSE AND $resultstring === '')
      {
        $resultstring = $onfailure;
      }
  
      // Check if there is {category_id} variable placed between {exp:category_id} and {/exp:category_id} tag pair
      if (strpos($tagdata, '{category_id}') > 0 OR strpos($tagdata, '{category_id}') === 0)
      {
        // If there is {category_id} variable, then return resultstring as variable's output
        $tagdata = str_replace('{category_id}', $resultstring, $tagdata); 
        $this->return_data = $tagdata;
      }
      else
      {
        // If there is no {category_id} variable, then return resultstring as output of single {exp:category_id} tag
        $this->return_data = $resultstring;
      }
    }
  }
  // END FUNCTION
  
// ----------------------------------------
//  Plugin Usage
// ----------------------------------------
// This function describes how the plugin is used.
//  Make sure and use output buffering

function usage()
{
ob_start(); 
?>

PARAMETERS:

1) category_group - (integer starting from 1). Required. Allows you to specify ID number of category group 
(the ID number of each category group is displayed in the Control Panel).

2) category_url_title - (any string which consists from characters legal for use in url segment). Required. 
Allows you to specify URL title of the category. 

3) on_failure - (any string which consists from characters legal for use in ExpressionEngine's tag parameter 
values). Optional. Allows you to specify what {exp:category_id} tag will output in case category group or 
category url title specified in parameters does not exist.

4) invalid_input - Optional. Accepts two values: “alert” and “silence”.
Default value is “silence”. If the value is “alert”, then in cases when some
parameter’s value is invalid plugin exits and PHP alert is being shown;
if the value is “silence”, then in cases when some parameter’s value
is invalid plugin finishes its work without any alert being shown. 
Set this parameter to “alert” for development, and to “silence” - for deployment. 

EXAMPLE OF USAGE:

If URL title of your category is "my_category" and id number of it's category group is "5"  
then you can use optionally either single tag as here

{exp:category_id category_group="5" category_url_title="my_category"}

or variable {category_id} within {exp:category_id}{/exp:category_id} tag pair as here

{exp:category_id category_group="5" category_url_title="my_category"}
{category_id}
{/exp:category_id}

Both will return id of the category which belongs to category group 5 and has URL title "my_category". 

Variable {category_id} within {exp:category_id}{/exp:category_id} tag pair is
more powerful because you can use it's output as parameter of other tag. For such use 
you must add parse="inward" parameter to {exp:category_id} tag.

For example, code as this will work

{exp:category_id category_group="5" category_url_title="{segment_3}" parse="inward"}
{exp:weblog:category_archive weblog="my_weblog" show="{category_id}"}
Some code
{/exp:weblog:category_archive}
{/exp:category_id}

If category group or category url title specified in parameters does not exist then the tag {exp:category_id} 
by default will return nothing. In case 'on_failure' parameter was defined, then, in such case
the tag will output what was specified as value of this parameter.

Place this tag in any of your templates.

<?php
$buffer = ob_get_contents();
	
ob_end_clean(); 

return $buffer;
}
// END USAGE

}
// END CLASS
?>

search in ee

// see also this page: http://monumentenzorgfryslan.nl/index.php/links_files/

{exp:search:advanced_form result_page="search/index"}
				<input type="text" name="keywords" class="searchtext" id="textfield" value="typ hier uw zoekterm" />
				<input type="hidden" name="search_in" value="everywhere" />
				<input type="hidden" name="where" value="any" />
				<input type="hidden" name="exact_match" value="" />
				<input type="hidden" name="weblog_id[]" value="2" />
				<input type="hidden" name="weblog_id[]" value="3" />
				<input type="hidden" name="weblog_id[]" value="4" />
				<input type="hidden" name="weblog_id[]" value="5" />
				<input type="hidden" name="cat_id[]" value="all" />
				<input type="hidden" name="date" value="0" />
				<input type="hidden" name="date_order" value="newer" />
				<input type="hidden" name="orderby" value="title" />
				<input type="hidden" name="sort_order" value="desc" />
				<input type="hidden" name="date_order" value="newer" />
				</td>
				<td>
				<input type="image" src="{site_url}images/uploads/search_button.jpg" name="submit" value="submit" class="searchbutton" />
				</td>
				</tr>
			</table>
{/exp:search:advanced_form}

set active button of main nav

// see also this page: http://monumentenzorgfryslan.nl/index.php/links_files/

<div id="menu">
				<ul>
				  <li><a href="{path="main/index"}section/informatie_over" {if {exp:topcategory:top} == 4}class="active"{/if}>INFORMATIE OVER</a></li>
				  <li><a href="{path="main/index"}section/dienstverlening" {if {exp:topcategory:top} == 5}class="active"{/if}>DIENSTVERLENING</a></li>
				  <li><a href="{path="main/index"}section/projecten" {if {exp:topcategory:top} == 6}class="active"{/if}>PROJECTEN</a></li>
				  <li><a href="{path="links_files/index"}">LINKS &amp; DOWNLOADS</a></li>
				  <li><a href="{path="main/index"}section/organisatie" {if {exp:topcategory:top} == 8}class="active"{/if}>ORGANISATIE </a></li>
				</ul>
		    </div>

header image in ee

// need to figure out more how this one works...

{if embed:header_image}
              <img src="/images/cat_headers/cat_home.jpg" border="0" alt="header" />
{if:else}
  {!-- CATEGORY IMAGE HERE --}
  {exp:weblog:category_heading weblog="pages"}
    {if category_image}
      <a href="{homepage}"><img src="{category_image}" border="0" alt="{category_name}" /></a>
    {if:else}
     <a href="{homepage}"><img src="/images/cat_headers/cat_informatie.jpg" border="0" alt="{category_name}" /></a>
    {/if}
  {/exp:weblog:category_heading}
{/if} 

Breadcrumb in EE with weblog and category

// see for example also http://monumentenzorgfryslan.nl/index.php/main/section/dienstverlening

<div id="breadcrumb">
				u bent hier: {if embed:breadcrumb}{embed:breadcrumb}{exp:weblog:category_heading weblog="pages" limit="1"}&nbsp;&gt;&nbsp;{category_name}{/exp:weblog:category_heading}{/if}
             </div>

Links and downloads connected to pages (in a pages weblog) as related entries

// Related entries: links & downloads

{!-- Links and downloads --}
	
	{exp:weblog:entries
	  weblog="pages"
	  disable="member_data|pagination|trackbacks"
	  rdf="off"
	}
		{if count == 1}
			<h2 class="links">Links</h2>
		{/if}
	  {related_entries id="pages_links"}
	    <a href="{links_link}" target="_BLANK" class="links">{links_description}</a>
	  {/related_entries}
	{/exp:weblog:entries}

{exp:weblog:entries
	  weblog="pages"
	  disable="member_data|pagination|trackbacks"
	  rdf="off"
	}
	
	  {if count == 1}
			<h2 class="links">Downloads</h2>
	  {/if}
	  {related_entries id="pages_downloads"}
	    {downloads_file}
	      <a href="{file_url}" target="_BLANK" class="links">{downloads_description}</a>
	    {/downloads_file}
	    <br/>
	  {/related_entries}
	{/exp:weblog:entries}