Archive

Archive for the ‘ExpressionEngine’ Category

ExpressionEngine: display a navigation menu if an entry is assigned a specific category.

June 29th, 2011

As an avid ExpressionEngine user, I like to dynamically generate as much as I can. This also includes the dynamic generation of navigation menus, naturally. However, there are times when I will use an entry as a static navigation menu by assigned it a specific URL TITLE (for example: whats_new or righthand_menu). Now, in the case of categories, how does one display this right-hand menu ONLY on entries of a weblog that are assigned a specific category? Here is how:

{!--Display right-hand menu ONLY if the entry has been assigned to the AUTOMOBILES category--}
{exp:query sql="select count(w.url_title) AS post_count from exp_weblog_titles w, exp_category_posts cp, exp_categories c where w.entry_id = cp.entry_id and cp.cat_id = c.cat_id and c.cat_url_title='automobiles_category' and w.url_title = '{segment_3}' limit 1"}

{/exp:query}

{!-- Display AUTOMOBILES right-hand menu --}

{exp:query sql="SELECT e1.title, e1.entry_date, e1.edit_date, e2.field_id_2 FROM exp_weblog_titles e1, exp_weblog_data e2 WHERE e1.entry_id = e2.entry_id and e2.weblog_id = 51 and e1.url_title = 'righthand_menu' LIMIT 1"}
{field_id_2}
{/exp:query}

So, what exactly does this do?
The first query retrieves the post count of any entries (in this case, the URL TITLE of the entry is in the third segment of the URL) that are assigned to a specific category (we are looking for 1 here; in fact, the LIMIT 1 line keeps the query from searching for anything greater, as our relevant choices are either 1 or 0). The count is then applied to a PHP variable called assignedCatVar.

If the assignedCatVar is = 1, then the next query grabs the contents of the right-hand menu entry and displays it appropriately on the page.

Simple and effective.

Thantos ExpressionEngine

ExpressionEngine search results: custom template paths for section URLs with categories

February 10th, 2011

We use ExpressionEngine on a number of supported sites, and I tend to use ExpressionEngine’s (EE) internal search mechanism whenever feasible. The search results are generated from path setting specified at Admin › Weblog Administration › Weblog Management › Edit Weblog Preferences› Path Settings › Search Results URL .

For example, setting the Search Results URL value to
{homepage}staff-members will create a SEARCH RESULT of http://mysite.com/staff-members/.

Easy enough, right?

Now, what do you do when you have a Weblog that contains category-based information. The specified Search Results URL does not take this information into account. So, if you have a weblog with a hard-coded path of http://mysite.com/staff-members/category1/johndoe , how do you get the category to show up in the search results?

I have a workaround on the RESULTS template in my SEARCH template group:

{exp:search:search_results}

<?php $autoPath = ‘{auto_path}’;

$lastSegment = basename($autoPath);

//Staff-member URL update, based on the category assigned to the entry

if(strpos($autoPath, ‘staff-members’)){

//variable to assign the category to the appropriate URL segment for the Rule

$catVar = 1;

$basename = ‘catPath’;

?>

{categories}

<?php

$tempname = $basename.$catVar;

$$tempname = “{category_url_title}”;

$catVar++;

?>

{/categories}

<?php $autoPath = “{homepage}”.”staff-members/$catPath1/$lastSegment”;

} ?>

<br /><span><?php echo $autoPath; ?></span>

</div>

{/exp:search:search_results}

So, if the staff-members URL segment exists in the specified URL’s path, the Category/Categories assigned to the Entry are obtained and then added to the URL, defined by the $autoPath variable.

It might not be the most elegant solution, but it works great for us.

Thantos ExpressionEngine