>整合Shopify和WordPress:綜合指南
許多小型企業依靠WordPress,但是Shopify越來越流行於基於產品的電子商務。 本教程演示瞭如何將您的Shopify商店無縫集成到現有的WordPress網站中,在不放棄當前平台的情況下顯示您的產品。 我們將利用Shopify API和自定義WordPress頁面模板。 可以使用該集成的工作演示[此處](如果可用,請插入演示鏈接)。 最終結果看起來像:
密鑰概念:
>
>標識您的收藏ID:是ID)。確保收藏包含產品。
/admin/collections/123456789
123456789
>
重要:
WordPress設置:
創建一個子主題(推薦):始終在兒童主題中工作,以防止更新期間覆蓋主題。
創建一個自定義頁面模板():page-shopify.php
在主題目錄中創建一個名為的新文件。 該文件將包含代碼以獲取和顯示您的Shopify產品。 下面提供了基本結構:page-shopify.php
<code class="language-php"><?php /** * Template Name: Shopify Product Feed */ get_header(); ?> <div id="primary" class="full-width"> <?php while ( have_posts() ) : the_post(); ?> <div id="post-<?php the_ID(); ?>" post_class>> <div class="entry-header"> <h1 class="page-title"><?php the_title(); ?></h1> </div> <div class="entry-content"> <?php the_content(); ?> <div class="row product-feed"></div> </div> </div> <?php endwhile; ?> </div> <?php get_footer(); ?></code>
>創建一個新頁面並分配模板:在WordPress管理中創建一個新頁面,然後選擇“ Shopify Product feed”模板。
>
部分中添加以下PHP代碼。 該代碼從Shopify API獲取產品數據,處理緩存並顯示產品。 (注意:這是一個簡化的示例。請參閱提供的完整功能代碼的github Gist)。
><div class="row product-feed"></div>
(本節需要大量的php代碼來獲取和顯示產品。由於長度約束,我不能在此處包含完整的代碼。請參閱原始文本中的GitHub GIST,以獲取完整代碼)
page-shopify.php
>樣式的輸出(CSS):添加CSS以樣式顯示產品顯示以匹配您的網站的設計。
結論:
以上是將Shopify API與WordPress一起使用的詳細內容。更多資訊請關注PHP中文網其他相關文章!