shopifyÔÚ²úÆ·Ò³ÃæÉÏÏÔʾ²úÆ·ÍÆ¼ö°ì·¨
ÔÚ²úÆ·Ò³ÃæÉÏÏÔʾ²úÆ·ÍÆ¼ö
×¢ÖØ
ÕâÊôÓڸ߼¶½Ì³Ì£¬£¬£¬£¬£¬£¬£¬£¬Shopify ²»ÌṩÏà¹ØÖ§³Ö¡£¡£¡£¡£¡£´Ë½Ì³ÌÒªÇóÄú¾ßÓÐ HTML¡¢CSS¡¢JavaScript ºÍ Liquid µÈ Web Éè¼ÆÓïÑÔµÄ֪ʶ¡£¡£¡£¡£¡£ÈôÊÇÄúÐèÒª×ÊÖú£¬£¬£¬£¬£¬£¬£¬£¬ÄÇôÄú¿ÉÒÔÕÐÆ¸ Shopify ר¼Ò¡£¡£¡£¡£¡£
±¸×¢
´Ë×Ô½ç˵ÓÃÓÚ¸´¹Å Shopify Ä£°å£¬£¬£¬£¬£¬£¬£¬£¬²»ÊÊÓÃÓÚ¡°Online Store 2.0¡±Ä£°å¡£¡£¡£¡£¡£
ÕÒµ½ÄúµÄÄ£°å¼Ü¹¹°æ±¾
̽Ë÷¡°Online Store 2.0¡±Ä£°å×Ô½ç˵
±¾½Ì³ÌÏÈÈÝÔõÑùÔÚ Debut Ä£°åÖÐÏò²úÆ·Ò³ÃæÌí¼Ó²úÆ·ÍÆ¼ö¡£¡£¡£¡£¡£ÈôÒªÏêϸÏàʶ²úÆ·ÍÆ¼öµÄÊÂÇé·½·¨£¬£¬£¬£¬£¬£¬£¬£¬Çë²ÎÔÄÔÚ²úÆ·Ò³ÃæÉÏÏÔʾ²úÆ·ÍÆ¼ö¡£¡£¡£¡£¡£
±¸×¢£ºÄ¬ÈÏÇéÐÎÏ£¬£¬£¬£¬£¬£¬£¬£¬ÒÔÏ Shopify Ä£°åµÄ×îа汾ÖаüÀ¨²úÆ·ÍÆ¼ö£º
Boundless
Brooklyn
Debut
Minimal
Narrative
Simple
Venture
ÈôÊÇÄúʹÓõÄÊÇÉÏ·½Ä³¸öÄ£°åµÄ¾É°æ±¾£¬£¬£¬£¬£¬£¬£¬£¬ÔòÄú¿ÉÒÔÔÚ¸üÐÂÄ£°åºóÏÔʾ²úÆ·ÍÆ¼ö£¬£¬£¬£¬£¬£¬£¬£¬¶øÎÞÐè×Ô½ç˵ģ°å´úÂë¡£¡£¡£¡£¡£
±¾Ò³Ïà¹ØÖ÷Ìâ
°ì·¨ 1£º½¨Éè
product-recommendations.liquid·ÖÇø°ì·¨ 2£ºÔÚ
product.liquidÄ£°åÖаüÀ¨¸Ã·ÖÇø°ì·¨ 3£º±à¼ÄúµÄ
theme.jsÎļþÒÔ±ãÒÔÒì²½·½·¨¼ÓÔØÍÆ¼ö°ì·¨ 4£º±à¼
theme.scss.liquidÎļþÒÔ½¨Éè¼ÓÔØ¶¯»£¨¿ÉÑ¡£¡£¡£¡£¡£©
°ì·¨ 1£º½¨Éè product-recommendations.liquid ·ÖÇø
PC£º
ÔÚ Shopify ºǫ́ÖУ¬£¬£¬£¬£¬£¬£¬£¬×ªµ½ÔÚÏßÊÐËÁ > Ä£°å¡£¡£¡£¡£¡£
ÕÒµ½Òª±à¼µÄÄ£°å£¬£¬£¬£¬£¬£¬£¬£¬È»ºóµã»÷²Ù×÷ > ±à¼´úÂë¡£¡£¡£¡£¡£
ÔÚ Sections Ŀ¼ÖУ¬£¬£¬£¬£¬£¬£¬£¬µã»÷Ìí¼ÓзÖÇø¡£¡£¡£¡£¡£
½«Ð·ÖÇøÃüÃûΪ
product-recommendations£¬£¬£¬£¬£¬£¬£¬£¬È»ºóµã»÷½¨Éè·ÖÇø¡£¡£¡£¡£¡£½«ËùÓÐÄÚÈÝÌæ»»ÎªÏ·½´úÂ룺
{% assign heading = 'You may also like' %} {% assign limit = 4 %} <div class="page-width product-recommendations" data-base-url="{{ routes.product_recommendations_url }}" data-product-id="{{ product.id }}" data-limit="{{ limit }}" data-section-id="{{ section.id }}" data-section-type="product-recommendations"> {% if recommendations.performed %} {% if recommendations.products_count > 0 %} <div class="section-header text-center"> <h2>{{ heading }}</h2> </div> <ul class="grid grid--uniform grid--view-items"> {% for product in recommendations.products %} <li class="grid__item small--one-half medium-up--one-quarter"> {% include 'product-card-grid', max_height: 250 %} </li> {% endfor %} </ul> {% endif %} {% else %} <div> <div></div> <div></div> <div></div> </div> {% endif %} </div>µã»÷ÉúÑÄ¡£¡£¡£¡£¡£
µ±ÔÚ²úÆ·Ò³ÃæÖзºÆð¸Ã·ÖÇøÊ±£¬£¬£¬£¬£¬£¬£¬£¬recommendations.performed ½«Îª false£¬£¬£¬£¬£¬£¬£¬£¬Òò½ñÌìÉúµÄ HTML ½«ÏÔʾ¼ÓÔØ¶¯»£º
<div class="page-width product-recommendations" data-base-url="/recommendations/products" data-product-id="123" data-limit="4" data-section-id="product-recommendations" data-section-type="product-recommendations"> <div class="product-recommendations__loading-dots"> <div class="product-recommendations__loading-dot"></div> <div class="product-recommendations__loading-dot"></div> <div class="product-recommendations__loading-dot"></div> </div> </div>
±¸×¢£ºÍƼöµÄ²úÆ·ÐèҪʹÓà JavaScript ¾ÙÐÐÒì²½¼ÓÔØ¡£¡£¡£¡£¡£Äú½«ÔÚ°ì·¨ 3£º±à¼ÄúµÄ theme.js ÎļþÒÔ±ãÒÔÒì²½·½·¨¼ÓÔØÍÆ¼öÖмÓÔØÍÆ¼öµÄ²úÆ·¡£¡£¡£¡£¡£
ÈôÊÇÄú²»ÏëÏÔʾ¼ÓÔØ¶¯»£¬£¬£¬£¬£¬£¬£¬£¬Çë¸ÄΪʹÓô˴úÂ룺
{% assign heading = 'You may also like' %} {% assign limit = 4 %} <div class="page-width product-recommendations" data-base-url="{{ routes.product_recommendations_url }}" data-product-id="{{ product.id }}" data-limit="{{ limit }}" data-section-id="{{ section.id }}" data-section-type="product-recommendations"> {% if recommendations.products_count > 0 %} <div class="section-header text-center"> <h2>{{ heading }}</h2> </div> <ul class="grid grid--uniform grid--view-items"> {% for product in recommendations.products %} <li class="grid__item small--one-half medium-up--one-quarter"> {% include 'product-card-grid', max_height: 250 %} </li> {% endfor %} </ul> {% endif %} </div>µ±ÔÚ²úÆ·Ò³ÃæÖзºÆðÉÏÊö·ÖÇøÊ±£¬£¬£¬£¬£¬£¬£¬£¬ÌìÉúµÄ HTML ½«Îª²»°üÀ¨ÈκÎÄÚÈÝµÄ div ÔªËØ£º
<div class="page-width product-recommendations" data-base-url="/recommendations/products" data-product-id="123" data-limit="4" data-section-id="product-recommendations" data-section-type="product-recommendations">
ÈôÊÇÓû§Ê¹ÓõÄÊDZ¸ÓÃÇøÓòÉèÖ㬣¬£¬£¬£¬£¬£¬£¬ÔòÇøÓòÉèÖý«°üÀ¨ÔÚ div µÄ data-base-url ÖС£¡£¡£¡£¡£ÀýÈ磬£¬£¬£¬£¬£¬£¬£¬/fr/recommendations/products¡£¡£¡£¡£¡£
Æ»¹ûϵͳ£º
ÔÚ Shopify Ó¦ÓÃÖУ¬£¬£¬£¬£¬£¬£¬£¬Çá´¥ÊÐËÁ¡£¡£¡£¡£¡£
ÔÚÏúÊÛÇþµÀ²¿·ÖÖУ¬£¬£¬£¬£¬£¬£¬£¬Çá´¥ÔÚÏßÊÐËÁ¡£¡£¡£¡£¡£
Çá´¥ Manage themes£¨ÖÎÀíÄ£°å£©¡£¡£¡£¡£¡£
ÕÒµ½Òª±à¼µÄÄ£°å£¬£¬£¬£¬£¬£¬£¬£¬È»ºóµã»÷²Ù×÷ > ±à¼´úÂë¡£¡£¡£¡£¡£
ÔÚ Sections Ŀ¼ÖУ¬£¬£¬£¬£¬£¬£¬£¬µã»÷Ìí¼ÓзÖÇø¡£¡£¡£¡£¡£
½«Ð·ÖÇøÃüÃûΪ
product-recommendations£¬£¬£¬£¬£¬£¬£¬£¬È»ºóµã»÷½¨Éè·ÖÇø¡£¡£¡£¡£¡£½«ËùÓÐÄÚÈÝÌæ»»ÎªÏ·½´úÂ룺
{% assign heading = 'You may also like' %} {% assign limit = 4 %} <div class="page-width product-recommendations" data-base-url="{{ routes.product_recommendations_url }}" data-product-id="{{ product.id }}" data-limit="{{ limit }}" data-section-id="{{ section.id }}" data-section-type="product-recommendations"> {% if recommendations.performed %} {% if recommendations.products_count > 0 %} <div class="section-header text-center"> <h2>{{ heading }}</h2> </div> <ul class="grid grid--uniform grid--view-items"> {% for product in recommendations.products %} <li class="grid__item small--one-half medium-up--one-quarter"> {% include 'product-card-grid', max_height: 250 %} </li> {% endfor %} </ul> {% endif %} {% else %} <div> <div></div> <div></div> <div></div> </div> {% endif %} </div>µã»÷ÉúÑÄ¡£¡£¡£¡£¡£
µ±ÔÚ²úÆ·Ò³ÃæÖзºÆð¸Ã·ÖÇøÊ±£¬£¬£¬£¬£¬£¬£¬£¬recommendations.performed ½«Îª false£¬£¬£¬£¬£¬£¬£¬£¬Òò½ñÌìÉúµÄ HTML ½«ÏÔʾ¼ÓÔØ¶¯»£º
<div class="page-width product-recommendations" data-base-url="/recommendations/products" data-product-id="123" data-limit="4" data-section-id="product-recommendations" data-section-type="product-recommendations"> <div class="product-recommendations__loading-dots"> <div class="product-recommendations__loading-dot"></div> <div class="product-recommendations__loading-dot"></div> <div class="product-recommendations__loading-dot"></div> </div> </div>
±¸×¢£ºÍƼöµÄ²úÆ·ÐèҪʹÓà JavaScript ¾ÙÐÐÒì²½¼ÓÔØ¡£¡£¡£¡£¡£Äú½«ÔÚ°ì·¨ 3£º±à¼ÄúµÄ theme.js ÎļþÒÔ±ãÒÔÒì²½·½·¨¼ÓÔØÍÆ¼öÖмÓÔØÍÆ¼öµÄ²úÆ·¡£¡£¡£¡£¡£
ÈôÊÇÄú²»ÏëÏÔʾ¼ÓÔØ¶¯»£¬£¬£¬£¬£¬£¬£¬£¬Çë¸ÄΪʹÓô˴úÂ룺
{% assign heading = 'You may also like' %} {% assign limit = 4 %} <div class="page-width product-recommendations" data-base-url="{{ routes.product_recommendations_url }}" data-product-id="{{ product.id }}" data-limit="{{ limit }}" data-section-id="{{ section.id }}" data-section-type="product-recommendations"> {% if recommendations.products_count > 0 %} <div class="section-header text-center"> <h2>{{ heading }}</h2> </div> <ul class="grid grid--uniform grid--view-items"> {% for product in recommendations.products %} <li class="grid__item small--one-half medium-up--one-quarter"> {% include 'product-card-grid', max_height: 250 %} </li> {% endfor %} </ul> {% endif %} </div>µ±ÔÚ²úÆ·Ò³ÃæÖзºÆðÉÏÊö·ÖÇøÊ±£¬£¬£¬£¬£¬£¬£¬£¬ÌìÉúµÄ HTML ½«Îª²»°üÀ¨ÈκÎÄÚÈÝµÄ div ÔªËØ£º
<div class="page-width product-recommendations" data-base-url="/recommendations/products" data-product-id="123" data-limit="4" data-section-id="product-recommendations" data-section-type="product-recommendations">
ÈôÊÇÓû§Ê¹ÓõÄÊDZ¸ÓÃÇøÓòÉèÖ㬣¬£¬£¬£¬£¬£¬£¬ÔòÇøÓòÉèÖý«°üÀ¨ÔÚ div µÄ data-base-url ÖС£¡£¡£¡£¡£ÀýÈ磬£¬£¬£¬£¬£¬£¬£¬/fr/recommendations/products¡£¡£¡£¡£¡£
°²×¿ÏµÍ³£º
ÔÚ Shopify Ó¦ÓÃÖУ¬£¬£¬£¬£¬£¬£¬£¬Çá´¥ÊÐËÁ¡£¡£¡£¡£¡£
ÔÚÏúÊÛÇþµÀ²¿·ÖÖУ¬£¬£¬£¬£¬£¬£¬£¬Çá´¥ÔÚÏßÊÐËÁ¡£¡£¡£¡£¡£
Çá´¥ Manage themes£¨ÖÎÀíÄ£°å£©¡£¡£¡£¡£¡£
ÕÒµ½Òª±à¼µÄÄ£°å£¬£¬£¬£¬£¬£¬£¬£¬È»ºóµã»÷²Ù×÷ > ±à¼´úÂë¡£¡£¡£¡£¡£
ÔÚ Sections Ŀ¼ÖУ¬£¬£¬£¬£¬£¬£¬£¬µã»÷Ìí¼ÓзÖÇø¡£¡£¡£¡£¡£
½«Ð·ÖÇøÃüÃûΪ
product-recommendations£¬£¬£¬£¬£¬£¬£¬£¬È»ºóµã»÷½¨Éè·ÖÇø¡£¡£¡£¡£¡£½«ËùÓÐÄÚÈÝÌæ»»ÎªÏ·½´úÂ룺
{% assign heading = 'You may also like' %} {% assign limit = 4 %} <div class="page-width product-recommendations" data-base-url="{{ routes.product_recommendations_url }}" data-product-id="{{ product.id }}" data-limit="{{ limit }}" data-section-id="{{ section.id }}" data-section-type="product-recommendations"> {% if recommendations.performed %} {% if recommendations.products_count > 0 %} <div class="section-header text-center"> <h2>{{ heading }}</h2> </div> <ul class="grid grid--uniform grid--view-items"> {% for product in recommendations.products %} <li class="grid__item small--one-half medium-up--one-quarter"> {% include 'product-card-grid', max_height: 250 %} </li> {% endfor %} </ul> {% endif %} {% else %} <div> <div></div> <div></div> <div></div> </div> {% endif %} </div>µã»÷ÉúÑÄ¡£¡£¡£¡£¡£
µ±ÔÚ²úÆ·Ò³ÃæÖзºÆð¸Ã·ÖÇøÊ±£¬£¬£¬£¬£¬£¬£¬£¬recommendations.performed ½«Îª false£¬£¬£¬£¬£¬£¬£¬£¬Òò½ñÌìÉúµÄ HTML ½«ÏÔʾ¼ÓÔØ¶¯»£º
<div class="page-width product-recommendations" data-base-url="/recommendations/products" data-product-id="123" data-limit="4" data-section-id="product-recommendations" data-section-type="product-recommendations"> <div class="product-recommendations__loading-dots"> <div class="product-recommendations__loading-dot"></div> <div class="product-recommendations__loading-dot"></div> <div class="product-recommendations__loading-dot"></div> </div> </div>
±¸×¢£ºÍƼöµÄ²úÆ·ÐèҪʹÓà JavaScript ¾ÙÐÐÒì²½¼ÓÔØ¡£¡£¡£¡£¡£Äú½«ÔÚ°ì·¨ 3£º±à¼ÄúµÄ theme.js ÎļþÒÔ±ãÒÔÒì²½·½·¨¼ÓÔØÍÆ¼öÖмÓÔØÍÆ¼öµÄ²úÆ·¡£¡£¡£¡£¡£
ÈôÊÇÄú²»ÏëÏÔʾ¼ÓÔØ¶¯»£¬£¬£¬£¬£¬£¬£¬£¬Çë¸ÄΪʹÓô˴úÂ룺
{% assign heading = 'You may also like' %} {% assign limit = 4 %} <div class="page-width product-recommendations" data-base-url="{{ routes.product_recommendations_url }}" data-product-id="{{ product.id }}" data-limit="{{ limit }}" data-section-id="{{ section.id }}" data-section-type="product-recommendations"> {% if recommendations.products_count > 0 %} <div class="section-header text-center"> <h2>{{ heading }}</h2> </div> <ul class="grid grid--uniform grid--view-items"> {% for product in recommendations.products %} <li class="grid__item small--one-half medium-up--one-quarter"> {% include 'product-card-grid', max_height: 250 %} </li> {% endfor %} </ul> {% endif %} </div>µ±ÔÚ²úÆ·Ò³ÃæÖзºÆðÉÏÊö·ÖÇøÊ±£¬£¬£¬£¬£¬£¬£¬£¬ÌìÉúµÄ HTML ½«Îª²»°üÀ¨ÈκÎÄÚÈÝµÄ div ÔªËØ£º
<div class="page-width product-recommendations" data-base-url="/recommendations/products" data-product-id="123" data-limit="4" data-section-id="product-recommendations" data-section-type="product-recommendations">
ÈôÊÇÓû§Ê¹ÓõÄÊDZ¸ÓÃÇøÓòÉèÖ㬣¬£¬£¬£¬£¬£¬£¬ÔòÇøÓòÉèÖý«°üÀ¨ÔÚ div µÄ data-base-url ÖС£¡£¡£¡£¡£ÀýÈ磬£¬£¬£¬£¬£¬£¬£¬/fr/recommendations/products¡£¡£¡£¡£¡£
°ì·¨ 2£ºÔÚ product.liquid Ä£°åÖаüÀ¨¸Ã·ÖÇø
ÈôÒªÔÚ²úÆ·Ò³Ãæµ×²¿ÏÔʾ²úÆ·ÍÆ¼ö£¬£¬£¬£¬£¬£¬£¬£¬ÇëÔÚ templates/product.liquid Îļþµ×²¿°üÀ¨¸Ã·ÖÇø£º
ÔÚ Templates Ŀ¼ÖУ¬£¬£¬£¬£¬£¬£¬£¬·¿ª product.liquid Îļþ¡£¡£¡£¡£¡£
ÔÚÎļþµ×²¿Ìí¼ÓÒÔÏ´úÂ룺
{% section 'product-recommendations' %}µã»÷ÉúÑÄ¡£¡£¡£¡£¡£
°ì·¨ 3£º±à¼ÄúµÄ theme.js ÎļþÒÔ±ãÒÔÒì²½·½·¨¼ÓÔØÍÆ¼ö
ÄúÐèÒª½«ÍƼö¼ÓÔØµ½¸Ã·ÖÇøÔÚ²úÆ·Ò³ÃæÉÏÌìÉúµÄ¿ÕÈÝÆ÷ÖС£¡£¡£¡£¡£Ê¹Óà JavaScript Ïò <base_url>?section_id=<section_id>&product_id=<product_id> ·¢³ö HTTP GET ÇëÇ󡣡£¡£¡£¡£
ÔÚ Assets Ŀ¼ÖУ¬£¬£¬£¬£¬£¬£¬£¬·¿ª theme.js Îļþ¡£¡£¡£¡£¡£
²éÕÒ´Ë´úÂëÐУº
sections.register('hero-section', theme.HeroSection);ÔÚ´ËÐÐÏ·½Ìí¼ÓÒÔÏ´úÂ룺
sections.register('product-recommendations', theme.ProductRecommendations);ÔÚÎļþµ×²¿Ìí¼ÓÒÔÏ´úÂ룺
theme.ProductRecommendations = (function() { function ProductRecommendations(container) { var $container = (this.$container = $(container)); var baseUrl = $container.data('baseUrl'); var productId = $container.data('productId'); var limit = $container.data('limit'); var productRecommendationsUrlAndContainerClass = baseUrl + '?section_id=product-recommendations&limit=' + limit + '&product_id=' +productId + ' .product-recommendations'; $container.parent().load(productRecommendationsUrlAndContainerClass); } return ProductRecommendations; })();µã»÷ÉúÑÄ¡£¡£¡£¡£¡£
°ì·¨ 4£º±à¼ theme.scss.liquid ÎļþÒÔ½¨Éè¼ÓÔØ¶¯»£¨¿ÉÑ¡£¡£¡£¡£¡£©
ÈôÊÇÄúʹÓÃÁË¿ÉÔÚ²úÆ·ÍÆ¼ö·ÖÇøÄÚÏÔʾ¼ÓÔØ¶¯»µÄ´úÂëÆ¬¶Ï£¬£¬£¬£¬£¬£¬£¬£¬ÇëÔÚ assets/theme.scss.liquid Îļþµ×²¿Ìí¼ÓÒÔÏ´úÂ룺
ÔÚ Assets Ŀ¼ÖУ¬£¬£¬£¬£¬£¬£¬£¬·¿ª theme.scss.liquid Îļþ¡£¡£¡£¡£¡£
ÔÚÎļþµ×²¿£¬£¬£¬£¬£¬£¬£¬£¬Ìí¼Ó´Ë´úÂ룺
.product-recommendations { padding-top: $section-spacing-small; padding-bottom: $section-spacing-small; @include media-query($medium-up) { padding-top: $section-spacing; padding-bottom: $section-spacing; } } .product-recommendations__loading-dots { height: 350px; display: flex; align-items: center; justify-content: center; } .product-recommendations__loading-dot { animation: dot-keyframes 1.5s infinite ease-in-out; background-color: $color-text; border-radius: 10px; display: inline-block; height: 10px; width: 10px; margin: 0 3px; &:nth-child(2) { animation-delay: 0.5s; } &:nth-child(3) { animation-delay: 1s; } } @keyframes dot-keyframes { 0% { opacity: 0.4; transform: scale(1, 1); } 50% { opacity: 1; transform: scale(1.2, 1.2); } 100% { opacity: 0.4; transform: scale(1, 1); } }µã»÷ÉúÑÄ¡£¡£¡£¡£¡£
ShopifyÉÌ»§¹ÙÍøÔÎÄÏêÇ飺
Show product recommendations on the product page
Caution
This is an advanced tutorial and is not supported by Shopify. Knowledge of web design languages such as HTML, CSS, JavaScript, and Liquid is required. If you need help, then you can hire a Shopify expert.
Note
This customization is for vintage Shopify themes, and doesn't apply to Online Store 2.0 themes.
Find out your theme's architecture version
Explore Online Store 2.0 theme customizations
This tutorial describes how to add product recommendations to your product page in the Debut theme. To learn more about how product recommendations work, see Showing product recommendations on product pages.
Note
The latest versions of the following Shopify themes include product recommendations by default:
Boundless
Brooklyn
Debut
Minimal
Narrative
Simple
Venture
If you're using an older version of one of these themes, then you can show product recommendations after you update your theme instead of customizing its code.
On this page
Step 1: Create a
product-recommendations.liquidsectionStep 2: Include the section in your
product.liquidtemplateStep 3: Edit your
theme.jsfile to load the recommendations asynchronouslyStep 4: Edit your
theme.scss.liquidfile to create the loading animation (optional)Step 1: Create a
product-recommendations.liquidsectionPC£º
From your Shopify admin, go to Online Store > Themes.
Find the theme you want to edit, and then click Actions > Edit code.
In the Sections directory, click Add a new section.
Name the new section
product-recommendationsand click Create section.Replace all of the content with the code below:
{% assign heading = 'You may also like' %} {% assign limit = 4 %} <div class="page-width product-recommendations" data-base-url="{{ routes.product_recommendations_url }}" data-product-id="{{ product.id }}" data-limit="{{ limit }}" data-section-id="{{ section.id }}" data-section-type="product-recommendations"> {% if recommendations.performed %} {% if recommendations.products_count > 0 %} <div class="section-header text-center"> <h2>{{ heading }}</h2> </div> <ul class="grid grid--uniform grid--view-items"> {% for product in recommendations.products %} <li class="grid__item small--one-half medium-up--one-quarter"> {% include 'product-card-grid', max_height: 250 %} </li> {% endfor %} </ul> {% endif %} {% else %} <div> <div></div> <div></div> <div></div> </div> {% endif %} </div>Click Save.
When the section is rendered with the product page,
recommendations.performedwill befalseand so the generated HTML will show a loading animation:<div class="page-width product-recommendations" data-base-url="/recommendations/products" data-product-id="123" data-limit="4" data-section-id="product-recommendations" data-section-type="product-recommendations"> <div class="product-recommendations__loading-dots"> <div class="product-recommendations__loading-dot"></div> <div class="product-recommendations__loading-dot"></div> <div class="product-recommendations__loading-dot"></div> </div> </div>
Note
The recommended products need to be loaded asynchronously using JavaScript. You will load them in Step 3: Edit your
theme.jsfile to load the recommendations asynchronously.
If you don't want to show a loading animation, use this code instead:
{% assign heading = 'You may also like' %} {% assign limit = 4 %} <div class="page-width product-recommendations" data-base-url="{{ routes.product_recommendations_url }}" data-product-id="{{ product.id }}" data-limit="{{ limit }}" data-section-id="{{ section.id }}" data-section-type="product-recommendations"> {% if recommendations.products_count > 0 %} <div class="section-header text-center"> <h2>{{ heading }}</h2> </div> <ul class="grid grid--uniform grid--view-items"> {% for product in recommendations.products %} <li class="grid__item small--one-half medium-up--one-quarter"> {% include 'product-card-grid', max_height: 250 %} </li> {% endfor %} </ul> {% endif %} </div>When the above section is rendered with your product page, the generated HTML will be a
divelement with no content:<div class="page-width product-recommendations" data-base-url="/recommendations/products" data-product-id="123" data-limit="4" data-section-id="product-recommendations" data-section-type="product-recommendations">If the user is using an alternate locale, then the locale is included in the div's
data-base-url. For example,/fr/recommendations/products.iPhone£º
From the Shopify app, tap Store.
In the Sales channels section, tap Online Store.
Tap Manage themes.
Find the theme you want to edit, and then click Actions > Edit code.
In the Sections directory, click Add a new section.
Name the new section
product-recommendationsand click Create section.Replace all of the content with the code below:
{% assign heading = 'You may also like' %} {% assign limit = 4 %} <div class="page-width product-recommendations" data-base-url="{{ routes.product_recommendations_url }}" data-product-id="{{ product.id }}" data-limit="{{ limit }}" data-section-id="{{ section.id }}" data-section-type="product-recommendations"> {% if recommendations.performed %} {% if recommendations.products_count > 0 %} <div class="section-header text-center"> <h2>{{ heading }}</h2> </div> <ul class="grid grid--uniform grid--view-items"> {% for product in recommendations.products %} <li class="grid__item small--one-half medium-up--one-quarter"> {% include 'product-card-grid', max_height: 250 %} </li> {% endfor %} </ul> {% endif %} {% else %} <div> <div></div> <div></div> <div></div> </div> {% endif %} </div>Click Save.
When the section is rendered with the product page,
recommendations.performedwill befalseand so the generated HTML will show a loading animation:<div class="page-width product-recommendations" data-base-url="/recommendations/products" data-product-id="123" data-limit="4" data-section-id="product-recommendations" data-section-type="product-recommendations"> <div class="product-recommendations__loading-dots"> <div class="product-recommendations__loading-dot"></div> <div class="product-recommendations__loading-dot"></div> <div class="product-recommendations__loading-dot"></div> </div> </div>
Note
The recommended products need to be loaded asynchronously using JavaScript. You will load them in Step 3: Edit your
theme.jsfile to load the recommendations asynchronously.
If you don't want to show a loading animation, use this code instead:
{% assign heading = 'You may also like' %} {% assign limit = 4 %} <div class="page-width product-recommendations" data-base-url="{{ routes.product_recommendations_url }}" data-product-id="{{ product.id }}" data-limit="{{ limit }}" data-section-id="{{ section.id }}" data-section-type="product-recommendations"> {% if recommendations.products_count > 0 %} <div class="section-header text-center"> <h2>{{ heading }}</h2> </div> <ul class="grid grid--uniform grid--view-items"> {% for product in recommendations.products %} <li class="grid__item small--one-half medium-up--one-quarter"> {% include 'product-card-grid', max_height: 250 %} </li> {% endfor %} </ul> {% endif %} </div>When the above section is rendered with your product page, the generated HTML will be a
divelement with no content:<div class="page-width product-recommendations" data-base-url="/recommendations/products" data-product-id="123" data-limit="4" data-section-id="product-recommendations" data-section-type="product-recommendations">If the user is using an alternate locale, then the locale is included in the div's
data-base-url. For example,/fr/recommendations/products.Android£º
From the Shopify app, tap Store.
In the Sales channels section, tap Online Store.
Tap Manage themes.
Find the theme you want to edit, and then click Actions > Edit code.
In the Sections directory, click Add a new section.
Name the new section
product-recommendationsand click Create section.Replace all of the content with the code below:
{% assign heading = 'You may also like' %} {% assign limit = 4 %} <div class="page-width product-recommendations" data-base-url="{{ routes.product_recommendations_url }}" data-product-id="{{ product.id }}" data-limit="{{ limit }}" data-section-id="{{ section.id }}" data-section-type="product-recommendations"> {% if recommendations.performed %} {% if recommendations.products_count > 0 %} <div class="section-header text-center"> <h2>{{ heading }}</h2> </div> <ul class="grid grid--uniform grid--view-items"> {% for product in recommendations.products %} <li class="grid__item small--one-half medium-up--one-quarter"> {% include 'product-card-grid', max_height: 250 %} </li> {% endfor %} </ul> {% endif %} {% else %} <div> <div></div> <div></div> <div></div> </div> {% endif %} </div>Click Save.
When the section is rendered with the product page,
recommendations.performedwill befalseand so the generated HTML will show a loading animation:<div class="page-width product-recommendations" data-base-url="/recommendations/products" data-product-id="123" data-limit="4" data-section-id="product-recommendations" data-section-type="product-recommendations"> <div class="product-recommendations__loading-dots"> <div class="product-recommendations__loading-dot"></div> <div class="product-recommendations__loading-dot"></div> <div class="product-recommendations__loading-dot"></div> </div> </div>
Note
The recommended products need to be loaded asynchronously using JavaScript. You will load them in Step 3: Edit your
theme.jsfile to load the recommendations asynchronously.
If you don't want to show a loading animation, use this code instead:
{% assign heading = 'You may also like' %} {% assign limit = 4 %} <div class="page-width product-recommendations" data-base-url="{{ routes.product_recommendations_url }}" data-product-id="{{ product.id }}" data-limit="{{ limit }}" data-section-id="{{ section.id }}" data-section-type="product-recommendations"> {% if recommendations.products_count > 0 %} <div class="section-header text-center"> <h2>{{ heading }}</h2> </div> <ul class="grid grid--uniform grid--view-items"> {% for product in recommendations.products %} <li class="grid__item small--one-half medium-up--one-quarter"> {% include 'product-card-grid', max_height: 250 %} </li> {% endfor %} </ul> {% endif %} </div>When the above section is rendered with your product page, the generated HTML will be a
divelement with no content:<div class="page-width product-recommendations" data-base-url="/recommendations/products" data-product-id="123" data-limit="4" data-section-id="product-recommendations" data-section-type="product-recommendations">If the user is using an alternate locale, then the locale is included in the div's
data-base-url. For example,/fr/recommendations/products.Step 2: Include the section in your
product.liquidtemplateTo display product recommendations at the bottom of your product page, include the section at the bottom of your
templates/product.liquidfile:
In the Templates directory, open the product.liquid file.
Add the following code at the bottom of the file:
{% section 'product-recommendations' %}Click Save.
Step 3: Edit your
theme.jsfile to load the recommendations asynchronouslyYou need to load recommendations into the empty container that the section produced on the product page. Use JavaScript to make an HTTP GET request to
<base_url>?section_id=<section_id>&product_id=<product_id>.
In the Assets directory, open the theme.js file.
Find this line of code:
sections.register('hero-section', theme.HeroSection);Below that line, add this code:
sections.register('product-recommendations', theme.ProductRecommendations);Add the following code at the bottom of the file:
theme.ProductRecommendations = (function() { function ProductRecommendations(container) { var $container = (this.$container = $(container)); var baseUrl = $container.data('baseUrl'); var productId = $container.data('productId'); var limit = $container.data('limit'); var productRecommendationsUrlAndContainerClass = baseUrl + '?section_id=product-recommendations&limit=' + limit + '&product_id=' +productId + ' .product-recommendations'; $container.parent().load(productRecommendationsUrlAndContainerClass); } return ProductRecommendations; })();Click Save.
Step 4: Edit your
theme.scss.liquidfile to create the loading animation (optional)If you used the snippet that shows a loading animation inside your product recommendations section, add the following code at the bottom of your
assets/theme.scss.liquidfile:
In the Assets directory, open the theme.scss.liquid file.
At the bottom of the file, add this code:
.product-recommendations { padding-top: $section-spacing-small; padding-bottom: $section-spacing-small; @include media-query($medium-up) { padding-top: $section-spacing; padding-bottom: $section-spacing; } } .product-recommendations__loading-dots { height: 350px; display: flex; align-items: center; justify-content: center; } .product-recommendations__loading-dot { animation: dot-keyframes 1.5s infinite ease-in-out; background-color: $color-text; border-radius: 10px; display: inline-block; height: 10px; width: 10px; margin: 0 3px; &:nth-child(2) { animation-delay: 0.5s; } &:nth-child(3) { animation-delay: 1s; } } @keyframes dot-keyframes { 0% { opacity: 0.4; transform: scale(1, 1); } 50% { opacity: 1; transform: scale(1.2, 1.2); } 100% { opacity: 0.4; transform: scale(1, 1); } }Click Save.
ÎÄÕÂÄÚÈÝȪԴ£ºShopifyÉÌ»§¹Ù·½ÍøÕ¾
- 1eBayÅÄÂôºóÄܲ»¿É¸ü¸Ä¼ÛÇ®£¿£¿£¿£¿£¿ÔõÑùÐ޸ģ¿£¿£¿£¿£¿
- 2Å·ÖÞÇ幨µÄÒ»Ð©×¢ÖØÊÂÏî
- 3ÑÇÂíÑ·×Ô¾õ»õµÄÎïÁ÷·½·¨
- 4ËÙÂôͨ²úÆ·¿¯µÇÔõÑùÎüÒýÂò¼Ò£¿£¿£¿£¿£¿
- 5shopeeµêËÁ¹Ø±ÕÊÇʲôԵ¹ÊÔÓÉ£¿£¿£¿£¿£¿ÊÇÔõô»ØÊ£¿£¿£¿£¿£¿
- 6¿ç¾³µç×ÓÉÌÎñµÄÉú³¤Ç÷ÊÆºÍÏà¹ØÕþ²ß
- 7 ÈôÊDz»Ð¡ÐÄÎ¥·´ÁËÑÇÂíÑ·°æÈ¨Õþ²ßÔõô°ì£¿£¿£¿£¿£¿ Ó¦¶Ô¼¼ÇÉÔÚÕâÀï
- 8¿ç¾³µçÉÌϵÄÍøÂçÓªÏúÇþµÀÓÐÄÄЩ
- 9ÑÇÂíÑ·Âô¼Ò¿ªµêÔËÓªÖÐÔõÑùʹÓÃÕ¾ÄÚÒýÁ÷£¿£¿£¿£¿£¿
- 10temuÈ«ÍйÜÈëפ»·½ÚÒÔ¼°±¸»õÒªÇó