ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Track views

November 25, 2011 5:26am

Subscribe [2]
  • #1 / Nov 25, 2011 5:26am

    kachunchau

    14 posts

    I’ve got a single template with conditionals to show a list of entries or a single one depending on the segments.

    Is there a way to track the views of the single entries by using conditionals? Track view works when I place the single entry code into a separate template but it doesn’t when I use the template below:

    {if segment_2 != "" AND segment_3 == ""}
       
       <!-- Manufacturer List --> 
          
       {if:elseif segment_3 != ""}
        
       <!-- Single entry--> 
             
       {if:else}
       
       <!-- Main list -->
          
       {/if}

    Thanks,
    Ka-Chun

  • #2 / Nov 27, 2011 7:03am

    Sean C. Smith

    3818 posts

    Hi kachunchau,

    What version of ExpressionEngine are you using? It would also be more helpful to see more of your template code - especially your channel entries tags and where you are putting the track view code.


    When using a single template to display multiple entries and a single entry sometimes things can get tricky. There are a couple of add-ons that can help make this better, both of them by Mark Corxton. Check out switchee and ifelse.

    Sean

  • #3 / Dec 05, 2011 4:44am

    kachunchau

    14 posts

    Sorry for the late reply but here’s the code I’m using and I’m using Expression Engine 2.3.1.

    {if segment_2 != "" AND segment_3 == ""}
       
       <!-- Manufacturer List --> 
          
       <form action="{path=equipment/search}" method="post">
        <input type="hidden" name="category" value="{segment_2}" />
        <input type="hidden" name="equipment_price-from" value="" />
        <input type="hidden" name="equipment_price-to" value="" />
        <ol>            
         {exp:super_search:search}
         <li><label for="sort">Sort by:</label>
           <select name="order">
              <option value="">--Please Choose--</option>
              <option value="equipment_price+asc">Price: Ascending</option>
              <option value="equipment_price+desc">Price: Descending</option>
           </select></li>
     
          <li class="hide"><button type="Submit">Sort</button></li>
          {/exp:super_search:search}
        </ol>
       </form>
       
       {exp:super_search:results channel="equipment" paginate="both" category="{last_segment_category_id}" limit="8" dynamic="off"}
       {if '{equipment_inventory}' > 0}
          
       <div class="equipment-entry">
        <div class="equipment-detail">
         <h2>{title}</h2>
    <p>    </p><h3>{categories show_group="1"}{category_name}{/categories} {categories show_group="2"}{category_name}{/categories}</h3>
    <p>    </div><br />
        <br />
        <div class="equipment-meta"><br />
        </p><h4>Only {equipment_price}</h4>
    <p>     <br />
         {embed="includes/test" related_ids="{equipment_manufacturer}"}<br />
         <br />
         <a href="http://{title_permalink={segment_1}/{segment_2}}">View</a><br />
        </div><br />
       </div><br />
       <br />
       {paginate}Page {current_page} of {total_pages} pages {pagination_links}{/paginate}<br />
       <br />
       {if:else}<br />
       {/if}<br />
       {/exp:super_search:results}<br />
        <br />
       <section class="browse-manufacturer"><br />
        </p><h3>Browse by manufacturer</h3>
    <p>        <br />
        <ul><br />
        {exp:channel:entries channel="manufacturer" dynamic="off"}<br />
         <li><a href="http://{title_permalink={segment_1}}">{title}</a></li> <br />
        {/exp:channel:entries}<br />
        </ul><br />
       </section><br />
          <br />
       {if:elseif segment_3 != ""}<br />
        <br />
       <!-- Single --> <br />
        <br />
       <div class="equipment-entry"><br />
          <br />
        {exp:channel:entries channel="equipment" limit="1" url_title="{segment_3}" dynamic="off" track_views="one"}<br />
      <br />
        {if equipment_image == ""}{equipment_image}{/if}<br />
            <br />
        <hgroup><br />
          </p><h2>{title}</h2>
    <p>      </p><h3>Only {equipment_price} (plus £99 handling charge)</h3>
    <p>    </hgroup><br />
        <br />
        <ul><br />
         <li>Fuel: {if equipment_fuel}{equipment_fuel}{if:else}N/A{/if}</li><br />
         <li>Mileage: {if equipment_mileage}{equipment_mileage}{if:else}N/A{/if}</li><br />
         <li>Transmission: {if equipment_transmission}{equipment_transmission}{if:else}N/A{/if}</li><br />
         <li>Reg date: {if equipment_reg_date}{equipment_reg_year}{if:else}N/A{/if}</li><br />
        </ul><br />
        <br />
        {if '{equipment_inventory}' > 0}<br />
        {embed="cart/.add_to_cart_form" <br />
        entry_id="{entry_id}" <br />
        template_group="cart"<br />
        no_tax="{if '{product_taxable}' == 'Yes'}0{if:else}1{/if}" <br />
        no_shipping="{if '{product_shippable}' == 'Yes'}0{if:else}1{/if}" }</p>
    
    <p>    {exp:cartthrob:add_to_cart_form <br />
         entry_id="{entry_id}" <br />
         return="cart"<br />
         price="99"}<br />
         <br />
         <input type="hidden" name="item_options[original_price]" value="{equipment_price:numeric}"><br />
         <input type="hidden" name="item_options[still_owed]" value="{exp:cartthrob:arithmetic expression="{equipment_price:numeric} + 99"}"><br />
         <button type="submit">Secure it for £99</button><br />
        {/exp:cartthrob:add_to_cart_form}<br />
        {if:else}<br />
        {/if}<br />
        <br />
        <section><br />
        </p><h4>Equipment Summary</h4>
    <p>     {equipment_summary}<br />
        </section><br />
        <br />
        <section><br />
        </p><h4>Specification</h4>
    <p>     {equipment_specification}<br />
        </section><br />
        <br />
        <section><br />
        </p><h4>Credientaials</h4>
    <p>     {equipment_credientials}<br />
        </section><br />
        <br />
       </div><br />
         <br />
       <form method="post" action="#"><br />
        <fieldset><br />
         <legend>Got a question or want to arrange a viewing?</legend><br />
         <br />
         <ol><br />
          <li><input type="text" name="name" /></li><br />
          <li><input type="email" name="email" /></li><br />
          <li><button type="submit">Get in touch</button></li><br />
         </ol><br />
        </fieldset><br />
       </form><br />
       <br />
       {if '{equipment_inventory}' > 0}<br />
           {embed="cart/.add_to_cart_form" <br />
           entry_id="{entry_id}" <br />
           template_group="cart"<br />
           no_tax="{if '{product_taxable}' == 'Yes'}0{if:else}1{/if}" <br />
           no_shipping="{if '{product_shippable}' == 'Yes'}0{if:else}1{/if}" }<br />
       <br />
       {exp:cartthrob:add_to_cart_form <br />
        entry_id="{entry_id}" <br />
        return="cart"<br />
        price="99"}<br />
        <br />
        <input type="hidden" name="item_options[original_price]" value="{equipment_price:numeric}"><br />
        <input type="hidden" name="item_options[still_owed]" value="{exp:cartthrob:arithmetic expression="{equipment_price:numeric} + 99"}"><br />
        <button type="submit">Secure it for £99</button><br />
       {/exp:cartthrob:add_to_cart_form}<br />
       {if:else}<br />
       {/if}<br />
       <br />
       {/exp:channel:entries} <br />
            <br />
       <section class="browse-manufacturer"><br />
        </p><h3>Similar trucks</h3>
    <p>    <br />
        <ul><br />
        {exp:channel:entries channel="equipment" category="{segment_2_category_id}"  limit="3" orderby="random" dynamic="off"}<br />
         <li></p><h4>{title}</h4>
    <p>      <a href="http://{title_permalink={segment_1}/{segment_2}}">View</a><br />
         </li><br />
        {/exp:channel:entries}<br />
        </ul><br />
       </section><br />
         <br />
       {if:else}<br />
       <br />
       <!-- Main list --><br />
       <br />
       {embed="includes/result_entries"}<br />
       <br />
       {/if}

  • #4 / Dec 06, 2011 7:44pm

    Sean C. Smith

    3818 posts

    Hi kachunchau,

    It’s possible track views isn’t working as expected due to the way the conditionals are being processed. Could you try using this add-on as it turns conditionals into early parsing. Another add-on to use with single templates running an entry and listing page is switchee. It’s somewhat complex but by all accounts very good.

    Sean.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases