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

About this user

Sasha http://nothing-less.net

« Newer Snippets
Older Snippets »
Showing 1-10 of 28 total  RSS 

Consistent Thumbnail Width

download system/core/core.image_lib.php, open it up in and editor and change:

var $master_dim            = 'height';

to
var $master_dim            = 'width'; 


This will resize all thumbnails to have the same width, regardless of their height (the EE default resizes them all to the same height, regardless of their width.)

Display list of Links (using LinkList Module)

Requires the LinkList module.

<ul>
{exp:linklist:entries linklist="links" orderby="url_title" sort="ASC" status="open" limit="30" paginate="both"}
<li class="topspaced">
 <span class="larger">{linklist:url_title}</span><br />
&nbsp;&nbsp;&nbsp;<img src="/images/icons/link.png" width="16" height="16" alt="Link" border="0" /> <a href="{linklist:url}">{linklist:url}</a><br />
&nbsp;&nbsp;&nbsp;<img src="/images/icons/tag_green.png" width="16" height="16" alt="Tags" border="0" />{keywords}<a href="{path="main/links"}">{keyword}</a> {/keywords}
</li>
{paginate}
			<p class="center">Page {current_page} of {total_pages} Pages {pagination_links}</p>
		{/paginate}
{/exp:linklist:entries}
</ul>

Gallery: Display a list of parent categories only

The below displays a list of all parent categories for a certain Gallery. Be sure to change the gallery_id if yours doesn't have an id of 1.

{exp:query sql="SELECT cat_id, cat_name FROM exp_gallery_categories WHERE gallery_id='1' AND parent_id='0' ORDER BY cat_order"}
<li><a href="{path=gallery/subcat}{cat_id}">{cat_name}</a></li>
{/exp:query}

Filter entries by custom field

It goes in mod.weblog.php.

Inside the build_sql_query() function.

Sandwiched between the ‘Add status declaration’ block and the ‘Build sorting clause’ block.

// ----------------------------------------------
//  Limit by custom weblog field
// ----------------------------------------------
if ($custom_field = $TMPL->fetch_param('custom_field'))
{
$custom_field_array= explode('|',$custom_field);

if ($custom_field_name = $custom_field_array['1'] AND $custom_field_value = $custom_field_array['0'])
{
if (isset($this->cfields[$custom_field_value]))
{
$custom_field_id = $this->cfields[$custom_field_value];
}

$sql .= "AND exp_weblog_data.field_id_".$custom_field_id." = '".$custom_field_name."' ";
}
}


You use it by passing string that looks like this:
custom_field_name|value


In the weblog tag parameter: custom_field

{exp:weblog:entries weblog="blog" custom_field="custom_field_name|value"}


Replace ‘custom_field_name’ with the name of the custom field your evaluating for. And replace ‘value’ with the value that the field needs to contain in order to fetch the relevant entries.

Hack at your own risk. No warranties, quarantees, or doggie fleas.

(code written by Solspace / http://www.pmachine.com/forums/viewthread/29199/)

Change the EE date fields to dropdown pickers

You can use the code below to change Expression Engine's custom date fields to easy dropdowns, instead of the confusing text fields.

JS in the head of your document:
<script language="JavaScript" type="text/javascript">
function entrydate()
{
	var month = document.entryform.start_month.value;
	var day = document.entryform.start_day.value;
	var year = document.entryform.start_year.value;
	var time = document.entryform.start_time.value;
	document.entryform.entry_date.value = year+month+day+" "+time;
}
</script>


Code for the actual fields:

<!-- Begin Month -->
<select name="start_month" onchange="entrydate();">
<option value="01-" >January</option>
<option value="02-" >February</option>
<option value="03-" >March</option>
<option value="04-" >April</option>
<option value="05-" >May</option>

<option value="06-" >June</option>
<option value="07-" >July</option>
<option value="08-" selected>August</option>
<option value="09-" >September</option>
<option value="10-" >October</option>
<option value="11-" >November</option>
<option value="12-" >December</option>

</select>
<!-- End Month -->

<!-- Begin Day -->
<select name="start_day" onchange="entrydate();">
<option value="1" >1</option>
<option value="2" >2</option>
<option value="3" >3</option>
<option value="4" >4</option>
<option value="5" >5</option>
<option value="6" >6</option>
<option value="7" >7</option>
<option value="8" >8</option>

<option value="9" >9</option>
<option value="10" >10</option>
<option value="11" >11</option>
<option value="12" >12</option>
<option value="13" >13</option>
<option value="14" >14</option>
<option value="15" >15</option>
<option value="16" >16</option>
<option value="17" >17</option>

<option value="18" >18</option>
<option value="19" >19</option>
<option value="20" >20</option>
<option value="21" >21</option>
<option value="22" >22</option>
<option value="23" >23</option>
<option value="24" >24</option>
<option value="25" >25</option>
<option value="26" >26</option>

<option value="27" >27</option>
<option value="28" >28</option>
<option value="29" >29</option>
<option value="30" selected>30</option>
<option value="31" >31</option>

</select>
<!-- End Day -->
<!-- Begin Year -->
<select name="start_year" onchange="entrydate();">
<option value="2005-" >2005</option>

<option value="2006-" selected>2006</option>
<option value="2007-" >2007</option>

</select>
<!-- End Year -->
<!-- Begin Time -->
<select name="start_time" onchange="entrydate();">
<option value="6:00 AM" >6:00 AM</option>
<option value="6:30 AM" >6:30 AM</option>
<option value="7:00 AM" >7:00 AM</option>
<option value="7:30 AM" >7:30 AM</option>

<option value="8:00 AM" selected>8:00 AM</option>
<option value="8:30 AM" >8:30 AM</option>
<option value="9:00 AM" >9:00 AM</option>
<option value="9:30 AM" >9:30 AM</option>
<option value="10:00 AM" >10:00 AM</option>
<option value="10:30 AM" >10:30 AM</option>
<option value="11:00 AM" >11:00 AM</option>
<option value="11:30 AM" >11:30 AM</option>
<option value="12:00 PM" >12:00 PM</option>

<option value="12:30 PM" >12:30 PM</option>
<option value="1:00 PM" >1:00 PM</option>
<option value="1:30 PM" >1:30 PM</option>
<option value="2:00 PM" >2:00 PM</option>
<option value="2:30 PM" >2:30 PM</option>
<option value="3:00 PM" >3:00 PM</option>
<option value="3:30 PM" >3:30 PM</option>
<option value="4:00 PM" >4:00 PM</option>
<option value="4:30 PM" >4:30 PM</option>

<option value="5:00 PM" >5:00 PM</option>
<option value="5:30 PM" >5:30 PM</option>
<option value="6:00 PM" >6:00 PM</option>
<option value="6:30 PM" >6:30 PM</option>
<option value="7:00 PM" >7:00 PM</option>
<option value="7:30 PM" >7:30 PM</option>
<option value="8:00 PM" >8:00 PM</option>
<option value="8:30 PM" >8:30 PM</option>
<option value="9:00 PM" >9:00 PM</option>

<option value="9:30 PM" >9:30 PM</option>
<option value="10:00 PM" >10:00 PM</option>
<option value="10:30 PM" >10:30 PM</option>
<option value="11:00 PM" >11:00 PM</option>
<option value="11:30 PM" >11:30 PM</option>

</select>
<!-- End Time -->
<input type="hidden" name="entry_date" value="2006-08-30 8:57 AM" />


Full credit for this goes to Solspace!

Restricr Search to a Member's Own Posts

Insert the below code just below the opening search form tags to restrict the search to a member's own posts if they are not a Super Admin.

{if group_id != "1"}<input type="hidden" class="input"  name="member_name" value="{screen_name}" />
{if:else}<p>You are logged in as a Super Admin, so all entries will be visible to you.</p>{/if}

Allow Admins access to member registration page

Open up mod.member_register.php, and look around line 69:

if ($SESS->userdata(’member_id’) != 1)
{
return $OUT->show_user_error(’general’, array($LANG->line(’mbr_you_are_registered’)));
}


Change the 0 to a 1 like shown above. :)

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).

{related_entries id="fieldid"}
<img src="{thumb_url}" width="{thumb_width}" height="{thumb_height}" alt="{title}" class="thumb" />
{/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. :)

<select name="field_id_13">{exp:query sql="SELECT field_list_items FROM exp_weblog_fields WHERE field_id = '13' "}
<?
$items ="{field_list_items}";
$items = explode("\n", $items); 
$howmany = count($items);
$i = 0; do { 
$item_id = $items[$i];
?>

<option value="<?=$item_id?>"><?=$item_id?></option>
<? 
 $i++; } while ($i < $howmany); ?>
{/exp:query}</select>

Linking to Stylesheets

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

<link rel="stylesheet" type="text/css" media="all" href="{stylesheet=static/style}" />

<link media="screen" type="text/css" href="{stylesheet=static/style}" />
« Newer Snippets
Older Snippets »
Showing 1-10 of 28 total  RSS