Even A Widgetifyr Stumps Me

widgetifyrlogo

A few days ago, Glenn Bennett got in touch with me to let me know about a site called Widgetifyr.com. This site is a service which aims at making the WordPress widget creation process much easier than creating the code from scratch every time.

If you’ve ever tried to turn your code into a wordpress plugin (which is how WordPress widgets get installed) you know it can get a bit tedious. Our service lets you just paste your code into a form along with some addition information and we “magically” turn it into a WordPress Plugin that allows your widget to be used in WordPress.

Immediately I thought this was a cool idea. So I took it for a test drive to see if I could create a widget using a regular WordPress function such as get_posts. As it turns out, even a widget generator can stump me.

creatingthewidget

The way this works is that you create a plugin file which you can download at the end, upload it to your plugins folder, activate it and then use the widget. So the first part of the process deals with the basic plugin stuff such as the name, version, author, etc. At the bottom of this page is the important part. This is where you name your PHP Function Name. In the text area, you’re supposed to paste your PHP code which would reside between the brackets. Here is what mine looked like.

phpfunctionname

I used this code from the example shown on the codex related to this function. Once that was done, I clicked on the create button which takes the function, wraps it with the widget code and then gives me the chance to view the code in a txt editor to copy, paste in my favorite editor and than save that file as get_posts.php. I then uploaded this file to my plugins folder. Upon activation, I was greeted with a fatal error:

Parse error: syntax error, unexpected ‘}’ in public_html/wptavern/wp-content/plugins/get_posts.php.php on line 33

Here is line 33.

line33

I received this error anytime I tried to activate a plugin I created. I’m not sure what I did wrong but after looking through the widgetifyr help page, to get a gist as to what the widget code is supposed to look like, and it’s obvious that you need to have a little PHP experience in order to really use this tool to its fullest potential.

The more I tinkered with the site, the more I realized that Otto’s Executable PHP Widget is a much easier, speedier solution for me. With this plugin, I can create widgets without having to worry about HTML or echoing anything. Here is one example of how I use this plugin.

widgetinaction

No copying of code, no uploading, and it just works (as long as I put the function in correctly). If you’re a coder, let me know if the service makes it easier for you to create widgets. As for myself, I’ll stick with a Otto’s solution.

5 Comments


  1. I looked at this a little while back and it looked like it could make things easier but I did think the wrapper around it made it look simpler than it would be. I guess you’ve proved me right.

    The thing is, there are some amazing widgets (Justin Tadlock’s for example) that let you run just about any query you want so it is hard to think of a situation where you would need to create your own.

    The problem with your code is that you started a loop but never closed it again, so PHP was expecting an endforeach and got the end of the function instead.

    Andrew’s last blog post..WLTC Plugin Competition: Max Image Size Control

    Report


  2. I could code a new widget in 10 minutes (assuming I already have my function(s) created). There’s really no need for developers to work with a widget creator, especially with the new widget class in WP 2.8. Things like this should be for Average Joe to use.

    Report


  3. Just commenting to say, yes, you should be using Justin’s Query Posts Widget. It’s super impressive.

    Report



  4. Jeff,

    Thanks for checking out our tool. I think you get a better idea of who would benefit from our tool by reading our post on the subject.

    Here’s the corrected code that would have made your widget work.

    Since we include your code as part of a function you need to get our of php mode “?>” and at the end you need to start php end with “<?PHP”.

    Also I finished out the loop for you. You just didn’t copy enough from the wordpress site.

    ?>
    
      < ?php global $post; $myposts = get_posts('numberposts=5&offset=1&category=1'); foreach($myposts as $post) : ?>
    • ">< ?php the_title(); ?>
    • < ?php endforeach; ?>
    < ?php

    I hope you find this useful.

    Glenn

    Report

Comments are closed.