• Tom

    (@jeffreeeeey)


    Hi,

    Firstly, thanks for this plugin it seems to be nice & lightweight and exactly what I was looking for.

    I’m using it on an eCommerce site I’ve been working on, but I now was to add a FAQ category to product pages within a category.

    Eg. If a product is in the “toys” category, it will display the “toys” FAQ’s… if a product is in the “Kitchenware” category it will show the “kitchenware” FAQ’s…

    As it stands at the moment I’d have to insert:
    [qa cat=”toys”] …to every product in the toys category, manually.

    Shortcodes are good for many things but for this particular site I have over 3,000 products to add, so anything to save me time would be a huge bonus.

    I’m thinking that if I can edit my product_listing.php (post template) with some php code/ if conditionals, I can achieve the needed – with your help of course ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Dalton Rooney

    (@daltonrooney)

    I think what you’re looking for is the do_shortcode function. Something like this:

    <?php echo do_shortcode([qa cat="dogs"]);?>

    You can use conditionals in your template and you can also replace the contents of the shortcode with variables; between those two you should have everything you need to automate this for thousands of products!

    Cheers,
    Dalton

    Thread Starter Tom

    (@jeffreeeeey)

    Thanks Dalton, that seems to work, but I’m struggling to understand how I use the conditionals for various categories (I have 8 different categories).

    Can you please give me an example of how to show a different shortcode for say, 3 categories?

    thanks

    Thread Starter Tom

    (@jeffreeeeey)

    OK here is what I have done… can anyone tell me if this is OK or if there is a better way of doing it?

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Plugin Author Dalton Rooney

    (@daltonrooney)

    If these are going on product pages and not on category index pages then I think you’ll want to use the in_category() conditional for all of them.

    And the correct format if you’ve got multiple categories is

    in_category( array( 1,2,3 ) )

    Dalton

    Thread Starter Tom

    (@jeffreeeeey)

    Thanks Dalton but it seems that code isn’t right in some way.. can you please re-post it inside code tags for me?

    Thread Starter Tom

    (@jeffreeeeey)

    Think I’ve got it…

    <!-- Lets show some FAQs based on the category a product is in --> 
    
    <?php if (in_category( array( 1,2,3 ) ) ) { ?>			<!-- primary category IDs go here -->
    <strong>Primary frequently asked questions</strong>
    <p><?php echo do_shortcode('[qa cat="faq-primary"]'); ?></p>
    
    <?php } elseif (in_category( array( 1,2,3 ) ) ) { ?>					<!-- secondary category IDs go here -->
    <strong>Secondary frequently asked questions</strong>
    <p><?php echo do_shortcode('[qa cat="faq-secondary"]'); ?></p>
    
    <?php } else { ?> 										<!-- display this (nothing) if not in any of above categories -->
    <p></p>
    <?php } ?>
    <!-- FAQ #end-->

    I would like to do the exact same thing, however my shortcode has no variables, I would just like to echo the content (what the user put between shortcode tags.

    Ive tried
    <?php echo do_shortcode('[sc]' . $content . '[/sc]'); ?>
    but it doesnt work

    anyone know how to do this?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Hard code instead of using shortcodes’ is closed to new replies.