Never been to TextSnippets 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

« Newer Snippets
Older Snippets »
Showing 21-40 of 52 total

CSS Switcher Code

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


<form action="" method="post">
<select name="css_skin" id="css_skin">
<option value="1">Option 1option>
/option>
select>/>
form>


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 Thisa>
{/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 Thisa>
{/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 {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> > {/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);
?>

Back and Forward Links in History

Using form buttons:

<form>
<input type="button" value="Back" onclick="history.back()">
<input type="button" value="Forward" onclick="history.forward()">
<input type="button" value="Reload" onclick="location.reload()">
form>


Using a normal link:

<a href="javascript:history.back();">Backa>


Trim/Remove Spaces

To remove multiple occurences of whitespace characters in a string an convert them all into single spaces, use this:


$text = preg_replace('/\s+/', ' ', $text);
?>


Strip whitespace (or other characters) from the beginning and end of a string

$variable = trim($variable);

How To Manually Update Cpanel

/scripts/upcp

/scripts/upcp --force

How To Restart Services

Restart Apache:
service httpd restart


Restart Services:
service chkservd restart


Restart Cpanel:
/etc/init.d/cpanel restart


Restart Bind:
service named start


Run anything in /scripts:
./scriptname

How To Locate Files

lsof | grep searchterm

How To Fix Bandwidth Updating

If bandwidth stats aren't updating:

/scripts/runweblogs username
/scripts/runlogsnow

How To Fix 403 Errors for public_html

If all the public_html folders got their permissions wrong:

chmod 755 /home/*/public_html

How To Empty /var

If /var is too full:

cd /var
du -sh *


If the log directory is the problem:

rm -f /var/log/*.1
rm -f /var/log/*.2
rm -f /var/log/*.3
rm -f /var/log/*.4


(The /var/log directory contains archived files that always end with a number: exim_mainlog.1. Any file ending with a number can be safely deleted.)

If the problem is with the exim_mainlog being too large, try rotating the logs:

/usr/sbin/logrotate -vf /etc/logrotate.conf


If you get an error about a duplicate log entry:

cd /etc/logrotate.d
rm -rf httpd.rpmorig.log


And try the rotate again.

If the problem is in spool:

cd /var/spool/exim/msglog
rm -rf *

How To Empty /usr

cd /usr/local/apache/domlogs/
rm -rf *.*
/scripts/restartsrv httpd

How To Empty /backup

If /backup/ is too full:

cd /backup/cpbackup/monthly/
rm -f *.gz
/scripts/restartsrv httpd


Check the space after this, and it should be fine.

« Newer Snippets
Older Snippets »
Showing 21-40 of 52 total