Serge's Technology View

Talk about Technologies, Software Architecture and Management

Posts Tagged ‘sidebar’

Create your first Widget for WordPress – Gallery 2 ImageBlock

Now I am going further with my experiment and modify PHP Text Widget to allow embedding Menalto Gallery 2 ImageBlock into your blog.

As a result here is for you to try is an actual widget which you can see used to show some of my gallery photos.
You can download widget here – Gallery 2 Widget.

Bellow are steps to follow in order to start using it.

  • Download a ZIP file from location above
  • Unpack it and upload folder into your WordPress plugin folder
  • Visit your WordPress Admin concole and enable Plugin under “Plugins” section
  • Now go to Presentation/Widgets. You will see a new widget available – “Gallery.2″. If you need more then 1 widget to be used in your blog, change a number of available Gallery.2 widgets to desired.
  • Drag “Gallery.2 widget from available list onto your sidebar and go into options by clicking a small button on the widget bar
  • You could specify SideBar widget name, location of your gallery and choose appearance of the ImageBlock in your blog. Description for items is self-explanatory otherwise go to your Gallery.ImageBlock configuration page to find more details about the options.

Enjoy.

Create your first Widget for WordPress – PHPText

There is my first WordPress Widget – PHP Text – Text Box which accepts arbitrary PHP code and can execute it inside sidebar block.
Another requirement is that it is only be allowed to be entered by Admin User.

I have started with the original code for Text Widget and adjusted it to include such restriction.

It has superseded my IFrame solution discussed in prior post and works well except that CSS is not yet applied.

What has been demonstrated by this little project:

  • how to register your own sidebar widget
  • how to support multiple instances of the same widget in the sidebar
  • how to manage widget options from popup options window in Widget  Manager section of your Blog Admin Panel
  • how to store/read widget options
  • how to make your widget properly appear at the sidebar
  • implement some basic user rights manager

If you’d like to use it in your blog, source code is available here – WordPress PHP Text Widget.

I hope this little example would help you started with Plug-in development for your WordPress Blog.

WARNING: Any code injections allowed by dynamic content comes with possible security risk. Please be cautious about what you allow to be executed by the PHP code specified in the widget. I would strongly suggest avoiding use of external sources you have no control over.

Create your first Widget for WordPress – Intro

As you can see this blog is hosted using WordPress 2.3 engine.
Aside from being free and all, it provides you with easy way to extend it using Widgets.
There is a long list of widgets created by different people over the time and you can find almost anything.
Well… almost… when it comes to personal preference especially a programmer, we might became very picky and I am not an exclusion from this.

I was looking for the widget which will allow me to integrate an ImageBlock from my Photo Gallery into a side bar and I have not find something which will satisfy me all the way.

If you are familiar with Menalto Gallery 2 Engine, then you might know what ImageBlock is a simple preformatted PHP code snippet which you can put in your site’s PHP code to inject HTML showing random (or other kind) of item from your photo collection. In addition you need to include reference to the stylesheet file into the header.
All configuration options are translated into query parameters which are then used by the snippet.
Good, nice, easy… except that WordPress does not allow to use PHP inside your Text Widget, neither there is some very simple widget available around which will allow you do such thing easy way. I am sure there is one but I have not found one up to this moment.

As a result I end up using IFrame for some time with external page embedded. Not very nice solution since IFrame is not to XHTML validator friendly when it comes to transparency and is not auto-sizable without dancing with JavaScript…

After finishing some design work with my blog layout I have decided it is time to create my first Side Bar Widget for WordPress and it happened to be a PHPText.

Valid XHTML 1.0 Transitional  Valid CSS!