vBulletin Mods

The Official vBulletin Modifications Site
https://www.vbulletin.org/forum/showthread.php?t=236245

[HOW-TO vB4] Create a Widget using Plugins and Templates
by Mythotical
18 Feb 2010 19:47

In this tutorial I am hoping to enlighten many in wondering how to do their own custom widget without confusion.

I came across someone needing help with a widget issue, they could not get javascript to work nor PHP in the widget so I dug right in, keep in mind this is my first widget so I was doing this blindly, but upon digging in I realized it was easy once I learned what each portion of the system did, only took about 15 or 20 mins to figure it out. So I feel anyone can learn to do a widget faster than their own modification.

Lets begin, keep in mind that this is explained on how I did it and if you have questions with any aspect explained or not then just ask, I will gladly answer.

Step 1. - Widget Creation

With this step you want to create your widget first, I prefered to create the widget first as it seemed logical but you can rearrange the steps once you are used to the system.

Go to: AdminCP > vBulletin CMS > Widgets

https://www.vbulletin.org/forum/external/2010/02/18.png

Step 1a. - Widget Creation - Details

Click Create Widget at the bottom of this new page.

https://www.vbulletin.org/forum/external/2010/02/19.png

We now have a new page with boxes for: Widget Type, Title, and Description. Lets get the boxes filled in.

Widget Type: Static HTML
Title: My Widget (Name your widget whatever you would like)
Description: Make the description explanatory of what this widget does.

https://www.vbulletin.org/forum/external/2010/02/20.png

Click Save to create your new widget.

Step 2. - Widget Location

You'll need to go to AdminCP > vBulletin CMS > Layout Manager

The new page will load, on this page you have a list of layouts you have created or default layout. Find the layout you want to have this widget appear on and click GO next to the dropdown that is in line with your layout you have chosen, make sure Edit is selected from the dropdown.

https://www.vbulletin.org/forum/external/2010/02/21.png

Step 2a. - Widget Select and Add

From the box to the left, you will see all available widgets that have been created. Select your newly created Widget and click the > that is the right of that box.

https://www.vbulletin.org/forum/external/2010/02/22.png

Step 2b. - Move Widget

Once you have added the widget, a new box will appear with your Widget's title, mine is titled My Widget. You can click the darker bar with your widget title in it to move it to which ever column you choose.

https://www.vbulletin.org/forum/external/2010/02/23.png

Then click Save at the bottom to save the location.

Step 3. - Configure Widget

Head back to your left menu and click on Widgets.

When the page loads, find your widget and at the far right click Configure as the screenshot shows below.

https://www.vbulletin.org/forum/external/2010/02/24.png

Step 3a. - Configure Widget Page

A box will popup and turn the background black. In this new window or box do the following.

Enter Static HTML: Empty the box of everything
Template Name: Enter the name of your template you plan to create for use with this widget.

https://www.vbulletin.org/forum/external/2010/02/25.png

Step 4. - Add Widget Template

Go to: AdminCP > Styles & Templates > Style Manager

https://www.vbulletin.org/forum/external/2010/02/26.png

On that page, find the style you want this widget to appear with, then from the drop down to the far right choose Add New Template.

https://www.vbulletin.org/forum/external/2010/02/27.png

Step 4a. - Template Information

When the Add New Template page loads fill the boxes as listed below.

Title: Enter the name of your template, it is the same name that you entered when configuring your widget in Step 3.
Template: Enter the following html into this area.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Click save once you have entered the template info.

https://www.vbulletin.org/forum/external/2010/02/28.png

Step 5. - Plugin Creation

Go to: AdminCP > Products & Plugins > Plugin Manager (You can create yourself a new product but if you are new to any type of vB modifying then I suggest you don't attempt to create a product)

https://www.vbulletin.org/forum/external/2010/02/29.png

On the new page, scroll to the bottom and click on Add New Plugin

https://www.vbulletin.org/forum/external/2010/02/30.png

Step 5a. - Plugin Info (Keep in mind this is for testing purposes)

On this page, fill in the boxes as provided below.

Product: Choose vBulletin CMS (If you created a product, choose it from the drop down)
Hook Location: global_start (Choose the plugin that fits best into where you want this to be shown, global_start is the best option for now)
Title: Give descriptive title
Execution Order: Leave this field alone
Plugin PHP Code:
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Plugin is Active: Set this to YES

Then click save and done

https://www.vbulletin.org/forum/external/2010/02/31.png

You are done. Now load your page and view your widget in action.

https://www.vbulletin.org/forum/external/2010/02/32.png

zanthor 25 Feb 2010 16:08

Unless I am completely out of my mind the hook global_start isn't nearly as global as one would hope... When I changed this to init_startup I got this working, global_start would fire on forums but not CMS...

Mythotical 25 Feb 2010 18:00

Zanthor, you are correct but what I used was an example. Nothing more. I left this article open for others to play around with it and try different things. The widget that I tested showed on the forumhome not the CMS.

Joseph Witchard 28 Feb 2010 02:31

How exactly do you know which hook to choose? I'm guessing you can probably see a complete list of all the hooks from that dropdown menu, but how are you supposed to know what each of them does and if it should be used for your particular mod?

Mythotical 28 Feb 2010 02:46

Well lets say you want to display info only when visiting a forum then it would be a forumdisplay, forumhome, etc type of hook. Global site would be init_start or global_start. Profile would be anything that has profile at the beginning. Basically each hook starts with the name of the part of the site it deals with.

Joseph Witchard 28 Feb 2010 03:11

So if several hooks started with the same thing, you would need to give your best guess as to which one would be the right one of your mod?

Mythotical 28 Feb 2010 03:21

Most have a start, end, complete, etc. Just depends on if you feel it will be best suited at start or complete. Usually you can open the file of the page your looking for, then find the hook of where it would fit into place.

heywho 01 Mar 2010 20:57

Hi, this is my first try at widget creation, and I'm a vB noob.... so this is pretty much over my head

Would like to create a widget using script


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

you can see the widget here :

Any help would be greatly appreciated... Thanks

Mythotical 05 Mar 2010 05:02

heywho: You would do it just the same way. I haven't tested it but the script code would go in the same place that html code would go in the template. If you tested it, I will attempt to figure it out once I've had some sleep.

Sorry for the delay, somehow the email regarding a new reply to this thread snuck by me.

Joseph Witchard 07 Mar 2010 03:23

Quote:

Originally Posted by Steve M (Post 1993376)
Most have a start, end, complete, etc. Just depends on if you feel it will be best suited at start or complete. Usually you can open the file of the page your looking for, then find the hook of where it would fit into place.

How do you know which page the hook is located in?

Mythotical 07 Mar 2010 16:01

If you want it on the profile only then fine a hook that begins with profile, you can open the .php file for that page then just find the hook that is closest to what you want. You can search the file for hook to find them.

Joseph Witchard 08 Mar 2010 03:24

Okay, this question might be a little late, but for the sake of understanding, I'm going to ask it anyway: what does a widget exactly do? I was a little confused by your end example on your first post.

heywho 10 Mar 2010 03:19

Quote:

Originally Posted by Steve M (Post 1997485)
heywho: You would do it just the same way. I haven't tested it but the script code would go in the same place that html code would go in the template. If you tested it, I will attempt to figure it out once I've had some sleep.

Sorry for the delay, somehow the email regarding a new reply to this thread snuck by me.

Hey, TY for info, I'll give it a try tonight.. sometimes, I forget I asked a questoin if I don't subscribe -- appretiate

Mythotical 11 Mar 2010 02:46

Quote:

Originally Posted by Joseph Witchard (Post 1999554)
Okay, this question might be a little late, but for the sake of understanding, I'm going to ask it anyway: what does a widget exactly do? I was a little confused by your end example on your first post.

A widget is simply an info box in a sidebar that you can have appear on your forum or CMS page.

heywho: No problem, good luck

Joseph Witchard 11 Mar 2010 03:10

Must you put it in a sidebar? Could you put it in the header, for example?


All times are GMT. The time now is 06:50.

Powered by vBulletin® Version 3.8.14
Copyright © 2020, MH Sub I, LLC dba vBulletin. All Rights Reserved. vBulletin® is a registered trademark of MH Sub I, LLC
Copyright ©2001 - , vbulletin.org. All rights reserved.