+ Reply to Thread
Results 1 to 12 of 12

Thread: creating a navigation block that lists categories

  1. #1
    Client
    Join Date
    Aug 2010
    Posts
    49
    Squirrelcart version
    v3.2.1

    creating a navigation block that lists categories

    Hello!

    I'd like to create a navigation block that lists recently created categories in descending order (most recent at the top, is what I'm trying to say).

    Is there a tutorial for this?

    Thanks!

    T

  2. #2
    Squirrelcart Staff Jamie's Avatar
    Join Date
    May 2002
    Posts
    6,719
    Squirrelcart version
    v3.3.7
    The category links that appear in the "Product Catalog" navigation block can be sorted via the instructions on this page:
    http://squirrelcart.com/help/?Changi...t%20Order.html

    To show newer categories at the top, you can sort by record_number - descending.

    That is not going to exclude categories that were created prior to a certain date.

  3. #3
    Squirrelcart Staff Jamie's Avatar
    Join Date
    May 2002
    Posts
    6,719
    Squirrelcart version
    v3.3.7
    If you want a separate navigation block that will display the newest categories, try this....

    1. Create a new navigation block

    2. Put this in the Content field:
    PHP Code:
    <div class="nav_link_container cat_links">
        <ul class="nav_links">
            <?php sc_category_links(sc_query('SELECT * FROM Categories ORDER BY record_number DESC LIMIT 0,5')); ?>
        </ul>
    </div>

    3. The 5 in the code above controls how many categories it will display. In this case, it will show links for the last 5 category records added.

    4. Add that navigation block to your storefront page

  4. #4
    Client Beery_Asst's Avatar
    Join Date
    Feb 2006
    Location
    Houston, TX
    Posts
    189
    Squirrelcart version
    v3.4.0
    Can one modify that code just a bit to display the most recent products added instead of categories in a navigation block?

  5. #5
    Squirrelcart Staff Jamie's Avatar
    Join Date
    May 2002
    Posts
    6,719
    Squirrelcart version
    v3.3.7
    PHP Code:
    <?php 
    $prods 
    sc_query('
        SELECT 
             record_number
            ,IF(Display_Name,Display_Name,Name) AS Name
        FROM
            Products
        WHERE
                Not_For_Sale !=1
        ORDER BY
            Date_Added_to_Cart DESC
        LIMIT
            0,5
    '
    );
    if (empty(
    $prods)) return;
    ?>
    <div class="nav_link_container cat_links">
        <ul class="nav_links">
            <?php foreach($prods as $prod): ?>
                <li>
                    <a href="<?php print get_product_url($prod['record_number'])?>"><?php print sc_htmlspecialchars($prod['Name'])?></a>
                </li>
            <?php endforeach; ?>
        </ul>
    </div>
    That will show the 5 newest products in a nav block.

  6. #6
    Client Beery_Asst's Avatar
    Join Date
    Feb 2006
    Location
    Houston, TX
    Posts
    189
    Squirrelcart version
    v3.4.0
    Thanks, that's great. One last requet. Where the " Not_For_Sale !=1" is....

    What would I add to it to get the right field where it would only display items where cost is not $0?

    I have a "Used Equipment" category where customers can submit items via email to me that I will post as a product. I don't sell it for them thus the $0 cost, but list the items on my website as a product to create a draw where people will come back periodically to check out stuff.

    Beery

  7. #7
    Squirrelcart Staff Jamie's Avatar
    Join Date
    May 2002
    Posts
    6,719
    Squirrelcart version
    v3.3.7
    Base_Price > 0
    as in:
    PHP Code:
    <?php 
    $prods 
    sc_query('
        SELECT 
             record_number
            ,IF(Display_Name,Display_Name,Name) AS Name
        FROM
            Products
        WHERE
            Not_For_Sale !=1
            AND Base_Price > 0
        ORDER BY
            Date_Added_to_Cart DESC
        LIMIT
            0,5
    '
    );
    if (empty(
    $prods)) return;
    ?>
    <div class="nav_link_container cat_links">
        <ul class="nav_links">
            <?php foreach($prods as $prod): ?>
                <li>
                    <a href="<?php print get_product_url($prod['record_number'])?>"><?php print sc_htmlspecialchars($prod['Name'])?></a>
                </li>
            <?php endforeach; ?>
        </ul>
    </div>
    </span>

  8. #8
    Client Beery_Asst's Avatar
    Join Date
    Feb 2006
    Location
    Houston, TX
    Posts
    189
    Squirrelcart version
    v3.4.0
    Thanks Jamie. Much appreciated.

    Beery

  9. #9
    Squirrelcart Staff Jamie's Avatar
    Join Date
    May 2002
    Posts
    6,719
    Squirrelcart version
    v3.3.7
    You're welcome

  10. #10
    Client
    Join Date
    Aug 2010
    Posts
    49
    Squirrelcart version
    v3.2.1

    Worked great!

    Thank, Jamie!

    This code is working great:

    <div class="nav_link_container cat_links">
    <ul class="nav_links">
    <?php sc_category_links(sc_query('SELECT * FROM Categories ORDER BY record_number DESC LIMIT 0,5')); ?>
    </ul>
    </div>

    One more question, I'd like to show the image associated with each category rather than just the name of the category. Is that possible?

  11. #11
    Squirrelcart Staff Jamie's Avatar
    Join Date
    May 2002
    Posts
    6,719
    Squirrelcart version
    v3.3.7
    The sc_category_links() function uses the product_catalog_nav_link.tpl.php template file to obtain the HTML for each link. You would need to alter that template file to add the category's image. You are going to find 2 anchor tags in that template, at line #10 and line #21. To change the name of the category to a link, you need to change:
    PHP Code:
    <?php print $Name ?>
    to:

    PHP Code:
    <img src="<?php print SC_IMG_DIR_DYN."/$Image" ?>" alt="<?php print $Name?>" />
    That will display the image you assigned to the category's "Image" field. If you want to use the "Image of Name" field instead, change that variable to "$Image_of_Name".

  12. #12
    Client
    Join Date
    Aug 2010
    Posts
    49
    Squirrelcart version
    v3.2.1

    Works great!

    Thanks Jamie!

    I added "$Thumbnail_Image" to show the thumbnail, and it looks nice!

    T

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts