Building a URL in the Search results
Posted: 16 July 2007 01:27 AM   [ Ignore ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1593
Joined  01-05-2007

I want to build a URL in the search results so is there any way of overriding the Weblog URL field?

 Signature 

 
Steven Hambleton | ExpressionEngine Development for Web & Graphic Design Agencies

Profile
 
 
Posted: 16 July 2007 11:12 AM   [ Ignore ]   [ # 1 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1593
Joined  01-05-2007

Hi Lisa,

Here is the code I have to create the categories on the right hand side of my site -

<ul id="product-list" class="content-right-links">
    
{exp:weblog:categories weblog="{segment_1}" show_empty="yes" style="linear"}
        
<li{if segment_4 == category_url_title} class="current_cat"{/if}><a href="{path={segment_1}/product}">{category_name}</a></li>
    
{/exp:weblog:categories}
</ul>

Here is the code to create a list of entries based on the category clicked on above -

{exp:weblog:entries weblog="{segment_1}"}
    
<div class="product">
        <
div class="product-photo">
            
{matting_photo}
        
</div> <!-- product-photo -->
        <
div class="product-details">
            <
h4 class="product-title"><a href="{path={segment_1}/product/}type/{categories}{category_url_title}{/categories}/{url_title}">{title}</a></h4>
            
{if matting_description}<p class="product-description">{matting_description}</p>{/if}
            {if matting_link}
<p><a href="{matting_link}?keepThis=true&TB_iframe=true&height=500&width=770" class="thickbox">View Offsite Product Information</a></p>{/if}
            
<ul class="product-specs">
                               
{if matting_sku}<li>Product Code: {matting_sku}</li>{/if}
                {if matting_dimension}
<li>Dimensions: {matting_dimension}</li>{/if}
                {if matting_guage}
<li>Guage: {matting_guage}</li>{/if}
                {if matting_length}
<li>Length: {matting_length}</li>{/if}
                {if matting_width}
<li>Width: {matting_width}</li>{/if}
                {if matting_lip
== "Yes" OR matting_lip == "No"}<li>Lip?: {matting_lip}</li>{/if}
                {if matting_type
== "Smooth" OR matting_type == "Spiked"}<li>Type: {matting_type}</li>{/if}
            
</ul>
        </
div> <!-- product-details -->
    </
div> <!-- product -->
{/exp:weblog:entries}

Finally, here is the code for my search results page -

<td class="{switch}"><a href="{auto_path}"{categories}{category_url_title}{/categories}>{title}</a></td>

Obviously the {auto_path} won’t do what I want it to. I want to preserve the URL structure when I click on a result in the search results so it has all 5 segments in the right order.

 Signature 

 
Steven Hambleton | ExpressionEngine Development for Web & Graphic Design Agencies

Profile
 
 
Posted: 16 July 2007 11:14 AM   [ Ignore ]   [ # 2 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32911
Joined  05-14-2004

{exp:search:search_results results="20"}
{if count
== "1"}<p>There are {total_results} results for <strong>{exp:search:keywords}</strong></p>{/if}

<p>{title}</p>
<
p>Link: {categories} <a href="{path="abracadabra/search"}{url_title}">{url_title}</a>{/categories}</p>

<
div class="posted">
{entry_date format="%l, %F %d, %Y"}
</div>



{/exp:search:search_results}

See in my example - try searching for “cat”. Note, I use category names in URLs.

 Signature 
Profile
MSG
 
 
Posted: 16 July 2007 11:19 AM   [ Ignore ]   [ # 3 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1593
Joined  01-05-2007

Ok let me try this…

 Signature 

 
Steven Hambleton | ExpressionEngine Development for Web & Graphic Design Agencies

Profile
 
 
Posted: 16 July 2007 11:25 AM   [ Ignore ]   [ # 4 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1593
Joined  01-05-2007

Ah yes! Almost there…

Is there a way to dynamically assign a template group? It did this ok with {path_auto} but not this method…

 Signature 

 
Steven Hambleton | ExpressionEngine Development for Web & Graphic Design Agencies

Profile
 
 
Posted: 16 July 2007 11:32 AM   [ Ignore ]   [ # 5 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32911
Joined  05-14-2004

I’ll need more information than that - is the template group per weblog, does it match the weblog shortname? How do *you* know what the correct template_group?

 Signature 
Profile
MSG
 
 
Posted: 16 July 2007 11:33 AM   [ Ignore ]   [ # 6 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1593
Joined  01-05-2007

Yes you got it. I have a weblog which shares the shortname as the template group.

 Signature 

 
Steven Hambleton | ExpressionEngine Development for Web & Graphic Design Agencies

Profile
 
 
Posted: 16 July 2007 11:41 AM   [ Ignore ]   [ # 7 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1593
Joined  01-05-2007

If only I could use this -

<td class="{switch}">{categories}<a href="{path={weblog_short_name}/product}{url_title}">{title}</a>{/categories}</td>

For some reason it won’t build a URL like that :(

 Signature 

 
Steven Hambleton | ExpressionEngine Development for Web & Graphic Design Agencies

Profile
 
 
Posted: 16 July 2007 11:50 AM   [ Ignore ]   [ # 8 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32911
Joined  05-14-2004

Yea, I just spent like 20 minutes trying to figure that out. {weblog_short_name} is working inside the categories variable pair but the path= is mucking it up.  I think this may be a bug, so I’ll need to research this.

A temporary fix would be to create a custom field for your category group for the templae group name, and fiill that out - it’s an extra step and would give you more flexibility but is a bit redundant if you always want to use the weblog shortname.  In any case, I’m going to look into this, as it should work.

 Signature 
Profile
MSG
 
 
Posted: 16 July 2007 11:56 AM   [ Ignore ]   [ # 9 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1593
Joined  01-05-2007

I’ll be happy if I managed to further the development of EE smile

In the meantime I’ll add the custom field. The project is not due for another month so hopefully the code gurus can get on the case and issue a new build or just drop me a bit of code to update.

 Signature 

 
Steven Hambleton | ExpressionEngine Development for Web & Graphic Design Agencies

Profile
 
 
Posted: 16 July 2007 01:02 PM   [ Ignore ]   [ # 10 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32911
Joined  05-14-2004

Ok, this isn’t a bug but rather a matter of parse order.  There are a few ways around it.

1) Category custom field as mentioned.
2) PHP
3) Making it even more manually built - though once its in the template, it doesn’t matter much:

{site_url}index.php/{weblog_short_name}/search/category/{category_url_title}/

Assuming you use category url titles and that “category” is your trigger word, etc.  So that takes path= totally out of the equation. =)  I’d personally go with option 3.

 Signature 
Profile
MSG
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 65027 Total Logged-in Users: 44
Total Topics: 82116 Total Anonymous Users: 23
Total Replies: 441310 Total Guests: 169
Total Posts: 523426    
Members ( View Memberlist )