Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

if sitting on sidebar-1, I need my widget to behave differently than if it were on sidebar-2. How can i detect the sidebar it is sitting on from within the widget() function?

The widget contains a list of links to posts. Depending on which sidebar, it should use a different custom image size version of its thumbnail.

So what will change is the thumbnail size reference name. For instance, in one sidebar, "xs-square-thumb" will be used; in another "L-square-thumb" will be used.

Ex: get_the_post_thumbnail($post->ID,'xs-square-thumb');

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

there isnt a clean way of handling this, since there isn't a conditional for checking which sidebar is in use, just whether or not it exists. however, you could do the following:

  1. make two different versions of the widget (which would make it "future proof" in regards to what widget names could exist).

  2. add a checkbox to the widget options to choose which size image to use.

share|improve this answer
    
GSto's answer is the correct one. –  Deryk Wenaus Mar 30 '13 at 2:03
add comment

You can check the 'id' variable that is passed in the $args variable in the widget() function, it will give you the id of the widgitized area it is currently in.

ex:

public function widget($args, $instance) {
  if( $args['id'] == 'sidebar-1' ) {
    //do sidebar stuff
  } else {
    //default behavior
  }
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.