vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   How to add php code into vb4 template? (https://vborg.vbsupport.ru/showthread.php?t=313423)

ozzy47 09-30-2014 10:04 AM

Best thing to do is to study a mod from here that does something similar.

kh99 09-30-2014 10:51 AM

Try this: create a plugin using hook location forumhome_start and code like this:

Code:

ob_start();
// insert code here without <?php or ?>
$backlinks = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('FORUMHOME', array('backlinks' => $backlinks));

as the comment says, insert the code you posted above, but remove the <?php from the beginning and the ?> from the end.

Next, edit the FORUMHOME template and insert {vb:raw backlinks} where you want it to appear.

Edit: if you want step by step instructions for creating a plugin, see the vbulletin manual here: http://www.vbulletin.com/en/manual/ . First select your vb version from the dropdown menu, then search for "plugin" and select "Adding or Editing a Plugin" from the results. It's pretty easy, you just have to paste the code I posted, then paste yours in at the comment and remove the <?php and ?>, then fill in the other form fields as needed (see the manual page for that). If you don't know what to put for something, you can probably leave the default.

postcd 10-01-2014 09:39 AM

Quote:

Originally Posted by kh99 (Post 2517051)
if you want step by step instructions for creating a plugin, see the vbulletin manual here: http://www.vbulletin.com/en/manual/ .

good post, but cant find the page where it is described, google also no help, would be good if you update your post to link to manual or better paste it into the post.

kh99 10-01-2014 09:42 AM

Yeah, sorry, it's just that the manual pages show in a frame so the browser url just goes to the manual home page. But I think this will work: http://www.vbulletin.com/docs/html/main/add_plugin

TheAdminMarket 10-01-2014 10:13 AM

As most of other users said, you can't add PHP code to the template. But you can easily add templates in a PHP file. The results will be exactly what you want.

1.- Create 2 templates. One for header and one for footer:

a] For Header (is just as example):
HTML Code:

<template name="php_header" templatetype="template" date="" username="" version="">
<![CDATA[
{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">

<head>
    <title>Your Title</title>
    {vb:raw headinclude}
    <vb:if condition="$vboptions['storecssasfile']">
        {vb:cssfile forumhome.css, options.css, vbcms.css, widgets.css, sidebar.css, forumhome-rollup.css, usercp.css, additional.css}
    <vb:else />
        {vb:cssfile forumhome.css, options.css, vbcms.css, widgets.css, sidebar.css, forumhome-rollup.css, usercp.css, additional.css}
    </vb:if>   
    <script type="text/javascript">
    <!--
        document.write('<script type="text/javascript" src="' + yuipath + '/animation/animation-min.js?v={vb:raw vboptions.simpleversion}"></script>');
        var sidebar_align = 'right';
        var content_container_margin = parseInt('{vb:math {vb:stylevar forum_sidebar_width}+{vb:math {vb:stylevar padding}*2}}');
        var sidebar_width = parseInt('{vb:stylevar forum_sidebar_width}');
    //-->

    </script>   
    <script type="text/javascript" src="{vb:raw vboptions.bburl}/clientscript/vbulletin-sidebar.js?v={vb:raw vboptions.simpleversion}"></script>
</head>
<body>
{vb:raw header}
{vb:raw navbar}
<div class="blockbody">
]]></template>

a] For Footer (is just as example):
HTML Code:

<template name="php_footer" templatetype="template" date="" username="" version="">
<![CDATA[
</div>

{vb:raw footer}
</body>
</html>
]]></template>

2.- In your PHP file (assuming that is a file which loads all vB functions that you need, add (again is an example):
Code:

// Header Block
$templater = vB_Template::create('php_header');
$templater->register_page_templates();
$navbits = construct_navbits(array("torget.php?" . $vbulletin->session->vars['sessionurl'] . ""=> "My Page"));
$navbar = render_navbar_template($navbits);
$templater->register('navbar', $navbar);
$header_block = $templater->render();
echo $header_block;

............Hera you can add any PHP code that you like..............
Code:

// Footer Block
$templater = vB_Template::create(php_footer');
$templater->register_page_templates();
$footer_block = $templater->render();
echo $footer_block;

Simple thing and works 100%. I build a complicated Ajax search form using this trick. And is 100% compatible with vBulletin meaning that you can use vboptions, vbphrase, datamanager etc.

Nick


All times are GMT. The time now is 02:02 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01167 seconds
  • Memory Usage 1,738KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (2)bbcode_html_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete