Thread tagged as: Problem, Shop

Getting Slug for Perch Shop

I'm just getting started with Perch Shop using vanilla Perch. I've gone through the initial setup, and have products displaying on my Shop page, when I specify a product slug on my individual product page that works as expected, but I'm having trouble getting it working for any product.

My product.php looks like this

<?php include('../perch/runtime.php');?>
<?php perch_layout('shop.header'); ?>

<div class="shop-header">
    <div class="container">

<div id="shop">

    <div class="container">

    <?php $product = perch_get('slug');

     perch_shop_product($product, [
            'template' => 'individual.html'
        ]); ?>

        <?php PerchUtil::output_debug(); ?>



<?php perch_layout('global.footer'); ?>

<?php perch_get_javascript(); ?>


My list.html is

    <div class="wrapper cols2-nav-right">

        <div class="primary-content">
<ul class="listing">
    <img src="<perch:shop id="image" type="image" label="Main product image" order="4" width="800" />" />
    <a href="/shop/<perch:shop id="slug" type="slug" />">
        <perch:shop id="title" type="text" />

    <perch:if not-exists="has_variants">
        <perch:form id="add_to_cart" app="perch_shop" action="/shop/cart.php">
            <perch:input id="product" type="hidden" value="<perch:shop id="productID" env-autofill="false" />" />
            <perch:input type="submit" value="Add to cart" />

I'm obviously not getting the slug correctly, but not sure why or how to fix it. I'd be grateful for any pointers.

Phil Bowell

Phil Bowell 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What's on your URL when it doesn't work?

The url is showing the slug, in this instance:


That slug matches the one displayed on the product in the admin.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello Phil,

perch_get('slug') looks for /?slug=your-product-slug.

Are you using any rewrite rules?

Hi Hussein,

I have some for shop yes.

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteRule ^shop/([a-zA-Z0-9-/]+)$ shop/product.php?s=$1 [L]

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Your rewrite is using ?s=, but you're using perch_get('slug') in your code. Try using perch_get('s') instead.

You sir, are a gentleman! It works now.

I think I had been using slug because that is the ID in product template.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer


For future reference, reading the perch_get() function documentation may be helpful: