Back to vBulletin 4 Articles

How to add a new field to the CMS
by Yellow Slider 22 Jan 2011
Rating: (2 votes - 3.50 average)

- Apply the changes mentioned in this how-to at your own risk.
- You must have a basic understanding of php, html and vbulletin.
- This is a how-to for vb4.1, and may not work on previous versions.

Everywhere you see FIELDNAME, replace it with your field name (must not contain spaces).

1.
Create a new field in the cms_node table.

2.
If you run vB 4.1.9 or lower , open packages\vbcms\item\content.php and find:
PHP Code:
return $pub_view
Add above it:
PHP Code:
$getFIELDNAME vB::$vbulletin->db->query_first("SELECT FIELDNAME FROM " TABLE_PREFIX "cms_node WHERE nodeid = " $this->nodeid);
$pub_view->FIELDNAME $getFIELDNAME['FIELDNAME']; 
If you run 4.1.10+, you can just create a new plugin with the above code, the hook is vbcms_content_publish_editor.

3.
Go to the template vbcms_edit_publisher.
At the bottom of the template, before these lines:
HTML Code:
</div>
<div style="clear:both"></div>
Add the following lines of code:
HTML Code:
	<div class="blockrow" >
		<label class="thirdleft">FIELD TITLE</label>
		<div class="twothirdsright"><input type="text" size="30" value="{vb:raw FIELDNAME}" name="FIELDNAME" tabindex="1" class="textbox fullwidth" /></div>
	</div>
4.
Go to your ACP --> Plugins & Products --> Add New Plugin.
Hook Location: vbcms_article_save_start.
PHP Code:
PHP Code:
vB::$vbulletin->input->clean_array_gpc('r', array(
    
'FIELDNAME' => TYPE_STR
));

vB::$vbulletin->db->query_write("UPDATE " TABLE_PREFIX "cms_node SET FIELDNAME = '" vB::$vbulletin->db->escape_string(vB::$vbulletin->GPC['FIELDNAME']) . "' WHERE nodeid = " $this->content->getNodeId()); 

The following steps have been written by Lynne, thank you

5. To get the field to spit out, you must add it to the vbcms_content_article_page somewhere (this is rough, you'll have to add your own class/styling).

HTML Code:
<div>Custom Field:{vb:raw FIELDNAME}</div>
6. Then, open vbcms/item/content/article.php and add your field to the end of the protected $content_properties array.
PHP Code:
'imageheight''previewvideo''FIELDNAME' 
7. In that same file, add this line with the other similar lines:

PHP Code:
protected $FIELDNAME
8. Again, in the same file, add this with the other similar functions:
PHP Code:
    public function getFIELDNAME()
    {
        
$this->Load(self::INFO_CONTENT);
        return 
$this->FIELDNAME;
    } 
9. Then add another plugin using hook_location "vbcms_article_populate_start":
PHP Code:
$view->FIELDNAME $this->content->getFIELDNAME(); 
I think I got that all correct.

That's it, you're done.

vblts.ru supports vBulletin®, 2022-2024