WordPress.org

Ready to get started?Download WordPress

Forums

AmazonSimpleAdmin
[resolved] Sidebar widget collection depending on article (4 posts)

  1. vguna
    Member
    Posted 1 year ago #

    Hi.

    Is it possible to configure the sidebar widget collection depending on a current post? So if I write an article about the new nexus 10, I would like to display just n related products specific to the nexus 10 - which I created manually before.

    http://wordpress.org/extend/plugins/amazonsimpleadmin/

  2. vguna
    Member
    Posted 1 year ago #

    I managed it via a little bit coding.

    I've created a text widget and entered the following code:

    <?php
    global $post;
    asa_collection('post_'.$post->ID,'all','sidebar_item');
    ?>

    The widget will show a collection which name is post_<postid>. So for a post with the id 5 it will display the collection with the name post_5.

    To test whether a collection exists for the post, and whether to display the widget at all, I'm using the plugin WidgetLogic.

    For the condition I set:

    is_single() && asa_existing_post_collection()

    The configured condition calls a custom function that I added to my wordpress installation:

    function asa_existing_post_collection() {
            global $post, $asa;
            $exist = $asa->getCollection('post_'.$post->ID,'all','sidebar_item');
            return $exist!='';
    }

    This allows me to show collections depending on a current post in the sidebar.

    The only caveat is: it has to render the collection twice. Once for the WidgetLogic and 2nd when displayed.

    I couldn't find a suitable public method to test for collections within amazon simple admin. Maybe one could be implemented in the future? Also it would be nice if one could specify the number of items to display when invoking asa via php directly.

  3. Timo Reith
    Member
    Plugin Author

    Posted 1 year ago #

    Great solution.
    I will provide a method to check if a collection exists with the next update. When the dev version is in the SVN I'll inform you.

  4. vguna
    Member
    Posted 1 year ago #

    Great thanks! Will the item count also be supported then :-)?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.