« Newer Snippets
Older Snippets »
22 total  XML / RSS feed 

Redirect after login

// This code allows you to use the free-standing login page to redirect members who login to individual start pages based on their group membership. Its use is explained in greater detail here:

http://www.firewhite.com/weblog/redirectafterlogin

// <?php global $SESS, $DB;


        {
                $memid = $SESS->userdata['member_id'];
                $group_no = $DB->query("select group_id from exp_members where member_id='$memid'");
                $group_num = $group_no->row['group_id'];
$login_path = '';
                $group_name = '';
                if($group_num == 1) {
                        $group_name = 'consultants';
                } else if($group_num <= 4) {
                        $group_name = 'default';
                } else {
                        $group = $DB->query("select group_title from exp_member_groups where group_id='$group_num'");
                        $group_name = str_replace(" ", "", strtolower($group->row['group_title']));
                        $group_name = preg_replace("/(.*)_.*/", "\\1", $group_name);
                        $template = $DB->query("select group_name from exp_template_groups where group_name like '$group_name'");
                        if ($template->num_rows < 1)
                                $group_name = 'default';

                }
            
        };
header("location: http://www.firewhite.com/$group_name/start"); exit();?>
    

?>

Site map, based on sections (e.g. weblogs) and categories

This will generate a site map using nested lists and h3 & h4 tags. Fairly rough, but serviceable.

{exp:query sql="SELECT blog_name, blog_title, blog_description FROM exp_weblogs"}
<h3><a href="{path={blog_name}}" title="{blog_description}">{blog_title}a></h3>
{exp:weblog:category_archive weblog="{blog_name} "style="nested" orderby="title"}
 {categories}<h4 id="{category_id}"><a href="{path={blog_name}/articles}" title="{category_description}">{category_name}a></h4>{/categories}
 {entry_titles}/detail}">{title}{/entry_titles}
{/exp:weblog:category_archive}
"separator">
{/exp:query}

Linking to Stylesheets

http://eedocs.pmachine.com/templates/globals/stylesheet.html

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

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


Using FlashObject and the miniFLV player to play videos from an entry

Ideally, at some point, I'll modify the plug-in for EE that shows Flash objects to use flashobject.js.

This code assumes custom fields in the blog.

FlashObject: http://blog.deconcept.com/flashobject/
MiniFLV: http://www.richnetapps.com/miniflv.htm

Online Example.

{if project_video}
{if project_video_title}<h4>{project_video_title}: Video Cliph4>{/if}

<div id="videoClip">
<p style="margin: 10px 0; padding: 10px; border: 3px solid red;"><a href="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank" title="Get Flash Player"><img src="http://www.macromedia.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Flash Player" height="31" width="88" align="left" style="padding-right: 10px">a>Flash 7 or above and JavaScript are required to view the project video clip. Please download the //www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank" title="Get Flash Player">latest Flash plug-in.

{if project_video_alt}

{project_video_alt}

{/if}
{/if}

Snippets Plugin

Coding to use for the Expression Engine Snippets Plugin:

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


In the header include (static/index in this case):
%page_title%
%page_section%

$fof_title="%nl_title%";
$fof_section="%nl_section%";
?>


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

Total Number of Entries for one Weblog

{exp:stats weblog="weblog1"}{total_entries}{/exp:stats}

Entry Date

{entry_date format="%F %d, %Y"}
{edit_date format="%F %d, %Y"}


More formatting options:
http://eedocs.pmachine.com/templates/weblog/variables.html#date_variables
http://eedocs.pmachine.com/templates/date_variable_formatting.html

Display In 2-Column Table

The below can be applied to MT, EE, etc, and will display the content in a 2 column table. The EE tags below are just an example, it will work equally well if you replace it with MT, Wordpress, etc, tags.

 $set_table="0"; ?>

<table cellpadding="5" border="0">
{exp:gallery:categories gallery="{gallery_name}"}
 
$fs_table = $set_table +1;
if ($set_table == "1") {echo"";} ?>


Insert other tags here.


 if ($set_table == "2") {echo"";  $set_table="0";} ?>
{/exp:gallery:categories}
</table>

Use PHP Inside EE Entries

You'll need the following plugins:
Allow EE Code: http://www.pmachine.com/plugins/allow-eecode/
Allow PHP: http://loweblog.com/archive/2005/06/03/ee-allow-php-plugin/

Set text formatting for the field you want to use this on to "None" (Admin > Weblog Administration > Custom Weblog Fields).

Change your template by adding the Allow EE tags around the field:

{exp:allow_eecode}{body}{/exp:allow_eecode}


Now you can use PHP inside your entries like this:

<p>Bla bla regular entry textp>

{exp:allowphp}
echo "This will be processed as PHP.";
{/exp:allowphp}

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}

Quick Cheat Sheet

DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Quick Cheat Sheettitle>





"WeblogIDs" cellpadding="5">
"heading">

{exp:query sql="SELECTweblog_id,blog_name,blog_title,blog_urlFROMexp_weblogsORDERBYblog_title"}

{/exp:query}
Full Weblog Name Short Name Weblog ID
{blog_title} {blog_name} {weblog_id}
"CustomFieldIDs" cellpadding="5"> "heading"> {exp:query sql="SELECTgroup_id,field_name,field_label,field_typeFROMexp_weblog_fieldsORDERBYfield_name"} {/exp:query}
Full Field Name Short Name Field Type
{field_label} {field_name} {field_type}
"CategoryIDs" cellpadding="5"> "heading"> {exp:query sql="SELECTcat_name,cat_id,group_idFROMexp_categoriesORDERBYgroup_id"} {/exp:query}
Full Category Name Category ID
{cat_name} {cat_id}


This EE code will create a quick Cheat Sheet that will list all your Weblogs with their short names and IDs, all your Custom Fields with their short names, and all your Categories with their IDs. This one page will save you having to look this up in the Admin panel constantly when editing/creating templates for your site. :)
Also posted at the EEWiki:
http://www.eewiki.com/wiki/Cheat_Sheet.

List all Weblogs

{exp:query sql="SELECT weblog_id, blog_name, blog_title, blog_url FROM exp_weblogs WHERE weblog_id != '100' ORDER BY blog_title"}
<li><a href="{blog_url}">{blog_title}a></li>
{/exp:query}


Lists all weblogs in one installation and shows how to exclude one by example.

Category Count

{exp:query sql="SELECT count(exp_category_posts.entry_id) AS count,exp_category_posts.cat_id, exp_categories.cat_name
FROM exp_categories, exp_category_posts WHERE exp_category_posts.cat_id = exp_categories.cat_id GROUP BY exp_categories.cat_name"}

<a href="{path=weblog/view}C{cat_id}/">{cat_name}
a> ({count})

{/exp:query}


Displays a list of categories with an entry count for each category. Alternatively, you can also use this query together with the {exp:weblog:categories} tag, making the query a lot smaller:

{exp:weblog:categories weblog="weblog1"}
<a href="{path=weblog/index}">{category_name}a>
{exp:query sql="SELECT count(exp_category_posts.entry_id) AS count
 FROM exp_category_posts  WHERE exp_category_posts.cat_id =  {category_id} "}
({count} entries)
{/exp:query}
{/exp:weblog:categories}
« Newer Snippets
Older Snippets »
22 total  XML / RSS feed