add code snippet in magento core - php

I'm running magento 1.4 and I'm trying to display an overlayer banner on all the pages in my magento store. In which file should I add the code snippet for the banner so that the it gets displayed on all pages?
BTW: the code snippet is actually some a short php if function + an OpenX Javascript Tag

From this search:
Go to /admin/cms_block/ and add a block. Remember the identifier.
In your code add <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('identifier')->toHtml() ?>
There you go…

For javascript to be included on every page have a look at page.xml layout <default> section. For PHP code see which blocks are included on the page and create a block after (or before) one of them

Related

Visual composer Masonry grid doesn't load

I'm using [insert_php] plugin in Wordpress and I have inserted php function in it.If I set the block with the function before the the masonry grid it doesn't load.
If I move the block with the function after the grid it works well.
In console log is appearing an alert:
Syntax error, unrecognized expression: {'status':'Nothing found'}
How can I sole that?
Grid before php block
Block php before the grid
What you need to do is create a page template. This page template can be used to create PHP for your page to load, and you can even use
<?php echo do_shortcode('[shortcode]'); ?>
To create a template just copy your page.php into a new file called tpl_test.php.
Then make sure to have this in the very first line:
`<?php
/*
Template Name: Test Template
*/
?>`
Then, a small window will show up on the back-end of WordPress when you edit the page. In the right hand column you need to select the page template for the page you just created, and update the page. then, any code you put in the custom Page Template will display correctly on your WordPress site. Also, make sure <?php the_content() ?> is below your grid you are trying to output.

Drupal variables in region templates

I'm doing my first totally custom Drupal 7 theme. I have the page.tpl.php file working fine and have header and footer regions working, until I move this:
<?php print render($page['main_menu']); ?>
into region--header.tpl.php - the menu is no longer generated - the html around the PHP is generated - nav etc. so I know drupal's reading the template file OK.
The same code works fine if it is in page.tpl.php
Any help greatly appreciated.
Main menu available as block. So you can just put him to this region. It's good practice.
Also don't forget to clear drupal/browser cache.
If you define custom variable in preprocess_page() or any other preprocess functions you shouldn't use render function, just use print $main_menu for example.
Also try check this

How to use shortcode in Magento phtml page

I have a short code
{{block type="ibtheme/product_list_featured" category_id="51" random_products="" template="catalog/product/list/featured.phtml"}}
which is working fine in editor from backend. How can U call the same short-code from a PHTML page ?
When I put the same code, it is printing a simple text.
phtml is php code, not cms html passed through a filter to catch the short codes (macros) and expand them out.
The contents between "{{" and "}}" must interpreted by a template engine and is only valid inside emails, CMS pages/blocks and the wysiwyg editors in the backend.
You put their equivalent into layout and call them as in the following ->
Magento Shortcode CMS block not working on product pages
In Magento CMS or Static block, if you want to add PHP code then you can just call any custom .phtml file by using following code. Like here I am including my_custom.phtml.
{{block type="core/template" name="myCustom" template="cms/my_custom.phtml"}}
This is equivalent to following layout tag:
<block type="core/template" name="myCustom" template="cms/my_custom.phtml">
Hope you find it useful.
The above answers are both incorrect if I'm reading that you would like to use shortcodes in phtml pages. I use these frequently, since we have a tremendous amount of content, and breaking them down in to phtml blocks is the easiest way for us to keep our content fresh.
Anyhow, here's the correct way to use call blocks in phtml:
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('cms/my_custom.phtml')->toHtml(); ?>
For Example, to use the block in your original answer would be
<?php echo $this->getLayout()->createBlock('ibtheme/product_list_featured')->setTemplate('catalog/product/list/featured.phtml')->toHtml(); ?>
I think this is what you're actually looking for. The code is in the CMS module in the Magento code.
<?php
// Load the cms helper
$helper = Mage::helper('cms');
// get the cms static block processor
$processor = $helper->getBlockTemplateProcessor();
// run the content with the shortcode through the filter
// in this case $item->getAnswer() contains a shortcode
$html = $processor->filter($item->getAnswer());
// print it to the page
echo $html;
?>
Remember anything is possible, just dig deeper. If in doubt, copy the Magento core code.

Adding a javascript to all pages in OpenCart

I'm new to OpenCart and don't have any experience with PHP, so I have a question. I want to add the following JavaScript to hide the url bar on mobile browsers
// When ready...
window.addEventListener("load",function() {
// Set a timeout...
setTimeout(function(){
// Hide the address bar!
window.scrollTo(0, 1);
}, 0);
});
However, I can't find a way to insert this so this code will be executed on all pages in OpenCart. Where should I put this code?
save your script to a file, say 'catalog/view/javascript/myscript.js'
Then add
$this->document->addScript('catalog/view/javascript/myscript.js');
to the catalog/controller/common/header.php some place before this line:
$this->data['scripts'] = $this->document->getScripts();
You could also just place your script inline into catalog/view/theme/{theme name}/template/common/header.tpl using normal html markup.
Looking at the theme documentation, I believe you want to edit the following file:
catalog/view/theme/{your-theme}/template/common/header.tpl
These templates (header, footer, etc) should appear on all pages.
You don't need to go through this trouble especially if you don't have access to FTP. All you need to do is just go to admin panel > design > theme editor > and choose the respective parts to insert the codes. If is footer then just choose footer.twig.
After adding the codes, click Save and you will see the changes immediately. If add the codes directly to the file on FTP, it won't work.
Tried and tested on OpenCart 3
To add a script like that, just go to admin panel > design > theme editor > select "common" > footer and in the end of the file (after </html>) add the script.
If you want script to all your pages of the OC just add it before footer tag in footer.tpl or footer.twig

Wordpress calling an HTML file from PHP

I am trying to modify a theme on wordpress. The theme shows a slider on the front page, which reads from the featured.php file.
I have gone into the featured.php and removed all the PHP code. I can inject my custom HTML into the featured.php and the pages display properly, however I want the page to display from a wordpress page.
So i tried to:
<?php
$html = file_get_contents('http://www.mydomain.com/homepage-featured');
?>
The above link corresponds to a page i created in wordpress. So i want to be able to inject my HTML into that page and then when you load my homepage, the PHP tells the browser to display the contents of this URL.
The above code doesn't work.
Thanks for the help.
file_get_contents() - as its name suggests - reads a file in but does not print it. You need to echo your $html variable. A better way is to use require() or include() but if I were you I would put my custom file on the same server so that way you don't have to use the file from a remote location thus sparing network traffic.
I think you have better to use the include function.
The file_get_contents you are using would generate an HTTP request, so it would make your script slower. I think it would be a good idea to put the HTML file on the same server if possible.
Have you tried
<?php
require('http://www.mydomain.com/homepage-featured');
?>
If my understanding is correct, you are trying to use a template (featured.php) for a different page other than the front page.
To do so, just change the Page Template of the page(the separate page which is # www.url.com/myhomepage). You can change this # Dashboard > Pages (Click Edit link in the required page) > Edit Page > Page Attributes meta box (available in the rightside below Publish) > Template. Change the template of this page to "Featured".
(I assume that your code in file feature.php has Template Name: Featured at the top)

Categories