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

About this user

Sasha http://nothing-less.net

CSS Switcher Code

{exp:css_switcher}<link rel='stylesheet' type='text/css' media='all' href='{file}' />{/exp:css_switcher}


<form action="<?php echo $_SERVER ['REQUEST_URI']; ?>" method="post">
<select name="css_skin" id="css_skin">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select><input type="submit" value="Set New Skin" />
</form>
<ul>
<li><a href="<?php echo $_SERVER ['REQUEST_URI']; ?>?css_skin=1">1</a></li>
<li><a href="<?php echo $_SERVER ['REQUEST_URI']; ?>?css_skin=2">2</a></li>
</ul>


Code for using the CSS Switcher plugin. Insert this anywhere in a EE template where you want this to show.

Edit Link In An Entry

Without the Snippets plugin (ie, straight on the template itself):

{if member_group == "1"}
<a href="/system/index.php?C=edit&M=edit_entry&weblog_id={weblog_id}&entry_id={entry_id}" title="Edit Entry">Edit This</a>
{/if}


With the Snippets plugin (ie, included in a seperate template that gets pulled into all other templates):

{if member_group == "1"}
<a href="/system/index.php?C=edit&M=edit_entry&weblog_id=%editweblog%&entry_id=%editweblog2%" title="Edit Entry">Edit This</a>
{/if}


And use this to include the editlink template:

{exp:snippets template="static/editlink"}
{editweblog}{weblog_id}{/editweblog}
{editweblog2}{entry_id}{/editweblog2}
{/exp:snippets}

Number of Entries in Galleries

All Galleries:
{exp:query sql="SELECT count(entry_id) AS count FROM exp_gallery_entries"}{count}{/exp:query}


One specific Gallery:
{exp:query sql="SELECT count(entry_id) AS count FROM exp_gallery_entries WHERE gallery_id=1"}{count}{/exp:query}

List of Stats

{exp:stats weblog="not 1|2"}
<ul>
<li>Since 2001, I have posted <strong>{total_entries}</strong> entries,</li>
<li>and received <strong>{total_comments}</strong> comments.</li>
<li><strong>{total_guests}</strong> people are currently browsing the site,</li>
<li>the most people online at the same time was <strong>{most_visitors}</strong> on <strong>{most_visitor_date format="%M %d, %y"}</strong>.</li>
</ul>
{/exp:stats}

Last Edited Entries

{exp:weblog:entries weblog="epguide" orderby="edit_date" limit="5"}
<h1>{title}</h1>
{/exp:weblog:entries}

Categories For One Entry

{categories backspace="4"}<a href="{path=weblog/index}">{category_name}</a> &gt; {/categories}

List All Entries

<ul>
{exp:weblog:entries weblog="weblog"}
<li><a href="{url_title_path=template/view}">{title}</a></li>
{/exp:weblog:entries}
</ul>


Content-sensitive, so putting this on a main index page will list all entries there are, on a category page all entries in that category, and on a date archive page all entries for that month.

List All Categories

{exp:weblog:categories weblog="name" show_empty="no" id="left_nav"}
<a href="{path="template"}">{category_name}</a>
{/exp:weblog:categories}

Trim a line of text to X characters

<? $varshort = substr($var,0,25); echo "$varshort"; ?>

Clean Up Form Input

<?
// trim spaces from the beginning and the end of the variable
$field_name = trim($field_name);

// strip all HTML from the variables
$field_name = strip_tags($field_name);

// change the case of the variable to capitalize (It Will Look Like This - handy for Name fields)
$field_name = ucwords(strtolower($field_name));

// change the case of the first character to uppercase, the rest to lowercase (It will look like this)
$field_name = ucfirst(strtolower($field_name));

//change the case of the variable to lowercase
$field_name = strtolower($field_name);

// change the case of the variable to uppercase
$field_name = strtoupper($field_name);
?>