Never been to DZone Snippets 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

« Newer Snippets
Older Snippets »
Showing 21-30 of 55 total

Relational Fields: Image Gallery Thumbnail

Use the code below to add a thumbnail version of the image gallery entry related to your current weblog entry (Expression Engine).

   1  
   2  {related_entries id="fieldid"}
   3  <img src="{thumb_url}" width="{thumb_width}" height="{thumb_height}" alt="{title}" class="thumb" />
   4  {/related_entries}

Dynamic Dropdown in the Stand Alone Entry Form

The problem: you are hand-coding the stand alone entry form, but it includes several dropdowns that you don't want to hand code. Here's a bit of coding to use for any dropdowns that you want to pull the options as filled in the Custom Fields area of the Admin panel.

In this example, I'm pulling the data for a field that has an ID of 13 - change this as needed. :)

   1  
   2  <select name="field_id_13">{exp:query sql="SELECT field_list_items FROM exp_weblog_fields WHERE field_id = '13' "}
   3  <?
   4  $items ="{field_list_items}";
   5  $items = explode("\n", $items); 
   6  $howmany = count($items);
   7  $i = 0; do { 
   8  $item_id = $items[$i];
   9  ?>
  10  
  11  <option value="<?=$item_id?>"><?=$item_id?></option>
  12  <? 
  13   $i++; } while ($i < $howmany); ?>
  14  {/exp:query}</select>

Linking to Stylesheets

How to link to a stylesheet created in Expression Engine (documentation).

   1  
   2  <link rel="stylesheet" type="text/css" media="all" href="{stylesheet=static/style}" />
   3  
   4  <link media="screen" type="text/css" href="{stylesheet=static/style}" />

Random Number

Replace 1 and 10 with the range you want to pick a number between. This example will pick a random number between 1 and 10.

   1  
   2  $randomnumber= rand(1,10);

clear default text onClick - restore if nothing entered

From ScriptyGoddess:
Clear default text onClick in forms using Javascript.

In your document's head:
   1  <script type="text/javascript">
   2  function clickclear(thisfield, defaulttext) {
   3  if (thisfield.value == defaulttext) {
   4  thisfield.value = "";
   5  }
   6  }
   7  function clickrecall(thisfield, defaulttext) {
   8  if (thisfield.value == "") {
   9  thisfield.value = defaulttext;
  10  }
  11  }
  12  </script>


The actual form field:
   1  <input type="text" name="myfield" onclick="clickclear(this, 'default text')" onblur="clickrecall(this,'default text')" />

Snippets Plugin

Coding to use for the Expression Engine Snippets Plugin:

In the actual pages:
   1  {exp:snippets template="static/index"}
   2  {page_title}Site: {title}{/page_title}
   3  {page_section}journal{/page_section}
   4  {/exp:snippets}


In the header include (static/index in this case):
   1  %page_title%
   2  %page_section%
   3  <?
   4  $fof_title="%nl_title%";
   5  $fof_section="%nl_section%";
   6  ?>


Define them as variables in PHP for easy if/else statements. :)

Search & Replace

   1  
   2  update tablename set field = replace(field,'search_for_this','replace_with_this');

Display Current Year

Useful for example for automatic copyright notices:

   1  
   2  &copy; Copyright 2004 - <?php echo date("Y") ?>

Date In The Future

How to display a date in the future - in this case, next month.

   1  
   2  <?php
   3   $nextmonth = mktime(0, 0, 0, date("m")+1, 1, date("Y"));
   4   echo date("F", $nextmonth);
   5   ?>

Total Number of Entries for one Weblog

   1  
   2  {exp:stats weblog="weblog1"}{total_entries}{/exp:stats}
« Newer Snippets
Older Snippets »
Showing 21-30 of 55 total