Content Egg Pro Plugin
Pricing
  • Content Egg WP Plugin
  • Getting started
    • Installation
    • Upgrade Free to Pro
    • Automatic updates
  • Modules
    • General information
    • Affiliate modules
      • Aliexpress module
      • Amazon module
      • Amazon No API module
      • Avantlink Products module
      • Awin module
      • Bestbuy module
      • Bolcom module
      • CityAds Products module
      • CJ Products module
      • Daisycon module
      • Ebay module
      • Envato module
      • Flipkart module
      • GdeSlon module
      • Impactradius module
      • Kelkoo module
      • Kieskeurignl module
      • Rakuten Linkshare module
      • Linkwise module
      • Lomadee Products module
      • Offer module
      • Optimisemedia module
      • Shareasale module
      • Shopee module
      • Tradedoubler Products module
      • Tradetracker Products module
      • Trovaprezzi
      • Udemy module (deprecated)
      • Sovrn (Viglink) module
      • Walmart module
      • Webgains module
    • Coupon modules
      • Admitad Coupons module
      • CJ Links module
      • Coupon module
      • Lomadee Coupons module
      • Skimlinks Coupons module
      • Tradedoubler Coupons module
      • Tradetracker Coupons module
    • Content modules
      • Bing Images module
      • Flickr module
      • Freebase module
      • Google Books module
      • Google Images module
      • Pixabay module
      • Qwant Images module
      • Related Keywords module
      • RSS Fetcher module
      • Twitter module
      • Youtube module
    • Feed modules
      • General information
      • Field mapping
      • Mass import
      • Price comparison based on feeds
      • Troubleshooting
    • Module cloning
    • Deprecated modules
    • My network isn't listed
    • Affiliate Egg integration
    • Deeplink settings
  • Set Up Products
    • How to add products
    • Price comparison websites
    • Autoblogging
    • Fill tool
    • Products page
    • How to add badge icons
  • Frontend
    • How content is displayed
    • 🆕Gutenberg blocks
    • 👉Shortcode parameters
    • Product groups/variations
    • Product sorting
    • Featured images
    • Frontend Search
    • Translation
    • Greenshift templates
  • Updating products
    • Price update
    • Product list update
    • Why prices don't update
    • Out-of-stock products
    • Price history
    • Price alert
    • Price movers
  • 🪄AI
    • Activating AI features
    • AI content generation
    • Smart groups
    • OpenAI API
    • Claude API
    • OpenRouter API
    • Custom prompts
  • WooCommerce Integration
    • General information
    • Product synchronization
    • Attributes synchronization
    • WooCommerce and autoblogging
  • Integrations
    • Affiliate Egg Integration
    • Cashback Tracker Integration
    • External Importer integration
    • WooCommerce Integration
  • Custom Templates
    • Customizing templates with CSS
    • How to install a custom template
    • 🪄ChatGTP Template Creator
    • How to create a custom template
  • Customization
    • Localization
    • For developers
    • Useful code snippets
    • REST API
    • Compatibility with themes
  • FAQ
    • How to add price comparison blocks to WooCommerce
    • How to add custom logos for merchants
    • How to import from CSV data feeds
    • How to change the date format or the date is not being displayed
    • Is Content Egg GDPR Compliant?
    • How to add offer count as a custom field
    • How to add products programmatically
  • Troubleshooting
    • Small font size in product blocks
    • Nothing found while search
Powered by GitBook
On this page
  1. Custom Templates

How to create a custom template

PreviousChatGTP Template CreatorNextLocalization

Last updated 6 months ago

This section is intended for developers. Basic knowledge of PHP and CSS is required to customize default templates or create your own templates.

Refer to the "" documentation section for instructions on creating templates using ChatGPT.

Content Egg templates combine HTML layout with PHP code to display product data. is embedded in the plugin by default, so you can use any Bootstrap CSS classes to ensure a responsive and modern design.

Steps to Create a Custom Template

  1. Starting Code:

    • Your template must start with the following code:

    <?php
    /*
     * Name: My template name
     * Modules:
     * Module Types: PRODUCT
     *
     */
    
    use ContentEgg\application\helpers\TemplateHelper;
    
    // This will include the Bootstrap 5 CSS file and the default plugin CSS file
    \ContentEgg\application\components\BlockTemplateManager::getInstance()->enqueueCeggStyle(true);
    
    ?>
    • Replace 'My template name' with the actual name of your template.

  2. Add a Div Container:

    • Next, add the following div container:

    <div class="cegg5-container">
    <!-- Inside this container, you can use Bootstrap 5 classes -->
    </div>
  3. Implement a Product Loop:

    • Implement a loop to iterate through and display all products:

    <?php foreach ($items as $key => $item) : ?>
    <!-- product data output here -->
    <?php endforeach; ?>
  4. Product Fields:

    • The $item array contains the following product fields:

      • unique_id

      • title

      • description

      • img

      • url

      • price

      • priceOld

      • currency

      • currencyCode

      • percentageSaved

      • manufacturer

      • rating

      • domain

      • merchant

      • logo

      • ean

      • images

      • subtitle

      • promo

      • shipping_cost

      • last_update

  5. Output Product Data:

    • To output product data, use the following snippets. Ensure to escape data output with the related WordPress functions.

Product Title:

<?php echo esc_html($item['title']); ?>

Product Affiliate URL:

<?php echo esc_url_raw($item['url']); ?>

Product Image:

<?php echo esc_attr($item['img']); ?>

Product Description:

<?php echo wp_kses_post($item['description']); ?>

Product Price:

<?php echo esc_html(TemplateHelper::formatPriceCurrency($item['price'], $item['currencyCode'])); ?>

Product Old Price:

<?php echo esc_html(TemplateHelper::formatPriceCurrency($item['priceOld'], $item['currencyCode'])); ?>

Merchant Domain:

<?php echo esc_attr($item['domain']); ?>

Merchant Logo URL:

<?php echo esc_attr(TemplateHelper::getMerchantLogoUrl($item, true)); ?>

Merchant Small Icon URL:

<?php echo esc_attr(TemplateHelper::getMerchantIconUrl($item, true)); ?>

Product Stock Status String:

<?php echo esc_html(TemplateHelper::getStockStatusStr($item)); ?>

Product Last Update Date Timestamp:

<?php echo esc_html($item['last_update']); ?>

Amazon Price Update Notice:

<?php TemplateHelper::priceUpdateAmazon($items); ?>

Affiliate Disclaimer:

<?php TemplateHelper::disclaimer(); ?>

Badge:

<?php TemplateHelper::badge2($item); ?>

Read next:

How to install a custom template

ChatGTP Template Creator
Bootstrap 5