• Resolved Gretchen Louise

    (@gretchenlouise)


    I’d love to make some suggestions for shortcode developments. Right now, I’m trying to code them myself (using the Views plugin by WP-Types), but to no avail.

    Here’s the thing: I don’t need a full-fledged bookstore on my site. But we are constantly recommending books, changing out the book covers in the sidebar that link straight to Amazon, and otherwise using book covers as Amazon ads throughout our site.

    My thought is that MyBookTable would make this so much easier. I’d love to be able to use a shortcode or widget to display specific or random book covers based on a certain tag, author, etc. BUT I want those book covers to link directly to Amazon. The shadow box and buy buttons seem like they are less likely to get clicked in on a sidebar ad than just a book image.

    I’d love to see shortcode/widget options for quantity of books and choosing order of books. i.e. 2 random books from the tag “stories”:
    [mybooktable tag="stories" quantity="2" orderby="random"]

    So far, I’ve gotten this far in Views. I have a View with this code:

    <wpv-loop>
    		<a href="http://www.amazon.com/dp/[wpv-post-field name="mbt_unique_id_asin"]?tag=myaffiliateid-20">
    <img src="[wpv-post-field name="mbt_book_image_id"]" alt="[wpv-post-title]"></a>
    	</wpv-loop>

    And it outputs this:
    <a href="http://www.amazon.com/dp/084231833X?tag=myaffiliateid-20"><img src="35915" alt="My Book's Title"></a>

    Obviously, the image id is not the image URL. And there are no custom fields visible to Views that show the image URL. I’ve peeked around in the functions, but I can’t use PHP in Views and so that gets beyond me.

    Any tips for an easy way to do this? Or hope that you’ll soon have features that would allow us to specify where the grid view/book covers link to?

    Thanks for any input!

    https://wordpress.org/plugins/mybooktable/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author zookatron

    (@zookatron)

    Thanks for your feedback. It’s great to see users doing unique things with MyBookTable.

    Unfortunately your particular use case differs enough from our core functionality that it’s not something that we would actively support out of the box in the plugin. As you say, you don’t need a “full-fledged bookstore”, but our primary goal is making a good full-fledged bookstore. Unfortunately we don’t have unlimited development time so we have to prioritize things that directly serve our primary goals.

    That said, I might be able to give you some tips to get you where you want to go.

    Unfortunately there is no way around needing to use PHP to get the image URL from the WordPress image ID. That’s just how WordPress works; It wants you to reference your image by ID, and then transform it into an actual image URL when you are ready to display it, which allows you to display different image sizes (which will have different urls) in different places (such as a small thumbnail on the archive page and a full sized image on the post itself) and to support responsive image sizing.

    However, you could cache a specific image URL for use with your Views template, which looks like it can only pull from preset post meta fields. You can do this by adding a hook to your theme that detects whenever a MyBookTable book is updated and caches the image URL into a new meta field. You would want to add something like the following snippet to your theme’s functions.php file:

    add_action('save_post', 'mytheme_cache_mbt_image', 20);
    function mytheme_cache_mbt_image($post_id) {
        if((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) or get_post_type($post_id) != "mbt_book") { return; }
        $image_url = '';
        // get the image id from the book's post meta
        $image_id = get_post_meta($post_id, 'mbt_book_image_id', true);
        // wp_get_attachment_image_src returns an array of image url, width, and height, if the image id exists
        $image_data = wp_get_attachment_image_src($image_id, 'mbt_book_image');
        // extract the image url from the data array, if the data was found
        if($image_data) { $image_url = $image_data[0]; }
        // create our custom post meta that contains the cached url
        update_post_meta($post_id, 'mytheme_cached_mbt_image', $image_url);
    }

    In order to get this work initially you will need to go in and re-save your MBT books in order to get this hook to run for each of them.

    ~Tim

    Hi All,

    I love this plugin as it helped me to cutshot the time, I have made some customization in this plugin file where I’M worried about the update. Becoz on updating all my custom code’s will not be updated, Also I tried adding those code’s in my theme’s child theme, but I couldn’t. The change’s which I have done is created a new taxanomy called “retailer’s” where we can filter books using the “stores”. Here are the file’s where I made changes.
    1. Widgets’php
    2. admin_pages.php.

    Please help me out to sort this problem.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘suggestions for shortcode options’ is closed to new replies.