Creating an HTML or PHP Widget

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lynne
    Former vBulletin Support
    • Oct 2004
    • 26255

    Creating an HTML or PHP Widget

    The is just a quick article with some examples for creating Static HTML and PHP Direct Execution Widgets

    Creating a Static HTML Widget

    First, create the widget:
    AdminCP > vBulletin CMS > Widgets > Create New Widget
    Widget Type: Static HTML
    Title: whatever you want
    SAVE

    Now, find your widget in the list and click on Configure Next to it and enter valid HTML into the text area there.

    Examples of HTML Widgets:
    Text:
    HTML Code:
    <p>Hello World</p>
    Click image for larger version

Name:	html1.png
Views:	1
Size:	11.1 KB
ID:	3719806

    An image:
    HTML Code:
    <img src="http://www.vbulletin.com/forum/images/misc/vbulletin4_logo.png" alt="" />
    Click image for larger version

Name:	html2.png
Views:	1
Size:	15.5 KB
ID:	3719807

    Youtube Video
    :
    HTML Code:
    <object width="240" height="240"><param name="movie" value="http://www.youtube.com/v/GpcJNEWKzCY&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/GpcJNEWKzCY&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="240" height="240"></embed></object>
    
    <br />
    Click image for larger version

Name:	html3.png
Views:	1
Size:	70.4 KB
ID:	3719805

    Creating a PHP Direct Execution Widget

    First, create the widget:
    AdminCP > vBulletin CMS > Widgets > Create New Widget
    Widget Type: PHP Direct Execution Widget
    Title: whatever you want
    SAVE

    Now, find your widget in the list and click on Configure Next to it and enter valid PHP into the text area there.

    Examples of PHP Direct Execution Widgets:
    Text:
    PHP Code:
    $output "Hello World"
    Click image for larger version

Name:	php1.png
Views:	1
Size:	12.1 KB
ID:	3719808
    Using a Variable:
    PHP Code:
    $output "Hello "vB::$vbulletin->userinfo['username'];
    $output .= "<br />How are you today?"
    Click image for larger version

Name:	php2.png
Views:	1
Size:	13.9 KB
ID:	3719809
    Using a query:
    PHP Code:
    $output "Hello "vB::$vbulletin->userinfo['username'];
    $output .= "<br />Your last post was in this thread:";
    $myquery =  vB::$db->query_first("
            SELECT
                post.threadid, thread.title 
            FROM " 
    TABLE_PREFIX "post AS post
            INNER JOIN " 
    TABLE_PREFIX "thread AS thread ON (thread.threadid = post.threadid)
            WHERE post.userid = "
    .vB::$vbulletin->userinfo['userid']. "
            ORDER BY post.dateline DESC
        "
    );
    $threadurl '<a href="' fetch_seo_url(thread$myquery) . '" title="'$myquery[title] .'">'$myquery[title] .'</a>';
    $output .= "<br />" $threadurl
    Click image for larger version

Name:	php3.png
Views:	1
Size:	16.9 KB
ID:	3719810
    Note: Depending on what your widget does, you may want to change the setting "Cache refresh time (minutes)" on the Configure screen also.

    If you need help writing the code for one of these widgets, you should request help over on vbulletin.org, the modification site.
    Last edited by Lynne; Fri 18 Feb '11, 10:29am.

    Please don't PM or VM me for support - I only help out in the threads.
    vBulletin Manual & vBulletin 4.0 Code Documentation (API)
    Want help modifying your vbulletin forum? Head on over to vbulletin.org
    If I post CSS and you don't know where it goes, throw it into the additional.css template.

    W3Schools &lt;- awesome site for html/css help
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Working...