Jump to content

add products list in sitemap.tpl


mrweb

Recommended Posts

Hi,

Take a backup of sitemap.tpl file before making any changes.

In sitemap.tpl file, you might need to add the code like below to add have div inside container-fluid div to show the product list in new column.

<div class="row sitemap-products col-xs-12">
  <div class="col-md-12">
    <h2>{$products_title}</h2>
    <ul>
      {foreach from=$products item=product}
      <li>
        <a href="{$product.link}" title="{$product.name}">{$product.name}</a>
      </li>
      {/foreach}
    </ul>
  </div>
</div>

In this snippet, replace {$products_title} with a string that you want to use as the title for the product list section in your sitemap. This title will be displayed above the list of products. The actual product names are fetched from the {$product.name} variable within the {foreach} loop.

After making changes, clear the cache and check.

Let me know If this works!
Thanks!

  • Like 1
Link to comment
Share on other sites

Hi

Thanks for your fast answer

I placed your code in sitemap.tpl

In the code I see this :
 

<div class="row sitemap-products col-xs-12">

<div class="col-md-12">

<h2></h2>

<ul> </ul>

</div>

</div>

The loop is empty, no products display

I attach the file

I have tried with this also, the result is empty again

<div id="products">   
            <div class="products row"> 
                {foreach from=$products item="product"}
                    {include file="catalog/_partials/miniatures/product.tpl" product=$product}
                {/foreach}
            </div>
</div>

Thanks for your help

sitemap.tpl

Link to comment
Share on other sites

Hi,

May be in custom controller, you need to fetch the product data and assign it to the template.

Sample code to be added in custom controller

class MyCustomSitemapModuleFrontController extends ModuleFrontController
{
    public function initContent()
    {
        parent::initContent();

        // Fetch product data.
        $products = $this->getProducts();

        $this->context->smarty->assign(array(
            'products' => $products,
            'products_title' => 'Products', // Set the title
        ));

        $this->setTemplate('sitemap.tpl');
    }

    // Method to fetch product data
    private function getProducts()
    {
        $products = array();
        $productList = Product::getProducts($this->context->language->id, 0, 0, 'id_product', 'ASC'); // This fetches a list of products
        foreach ($productList as $product) {
            $products[] = array(
                'name' => $product['name'],
                'link' => $this->context->link->getProductLink($product['id_product'])
            );
    	}
    	return $products;
    }
}

 

After we get the product data from the controller, we can use it in tpl to display.

Let me know If this helps!
Thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...