Include Sidebar Generator plug-in into my WP theme - include

I'm trying to include this plug-in:
http://wordpress.org/extend/plugins/sidebar-generator/
Into my wordpress theme. As many people around the internet said, I just included the sidebar_generator.php file into my functions.php. The 'Sidebars' menu appears under appearance, but no matter what I do, If I click on it nothing happens (just like it was linked on a '#').
If I install the plug-in through the wordpress interface everything works, I need to have it integrated though.
Any help?
Thank you

You shouldn't need a plugin to have extra sidebars. You should be able to build a theme template with as many sidebars as you want. When I'm creating a custom theme in WordPress I use a variation of the 960 CSS Grid (another good one is the newer 1140px CSS Grid System, which is fluid).
To register your sidebars to accept widgets, insert this code in your functions.php file:
// Widget Areas //
if ( function_exists('register_sidebars') ) {
// Primary sidebar widget
register_sidebar( array(
'name' => __( 'Blog Sidebar', 'unique' ),
'id' => 'blog-sidebar',
'description' => __( 'The sidebar widget area for the blog.', 'unique' ),
'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => __( 'Left Sidebar', 'unique' ),
'id' => 'left-sidebar',
'description' => __( 'The left sidebar widget area for pages.', 'unique' ),
'before_widget' => '<li id="%1$s" class="greenGradient widget-container %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widget-title greenbar center">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => __( 'Right Sidebar', 'unique' ),
'id' => 'right-sidebar',
'description' => __( 'The right sidebar widget area for pages.', 'unique' ),
'before_widget' => '<li id="%1$s" class="redGradient widget-container %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widget-title redbar center">',
'after_title' => '</h2>',
) );
}
In this case, I have a registered sidebar for just the blog, then one each for a right sidebar and a left sidebar.
In my theme directory I have three sidebar.php files. The blog sidebar file is the default sidebar.php file. The other two are named sidebar-left.php and sidebar-right.php. Each sidebar has it's appropriate code as follows:
<?php // blog widget area
if ( is_active_sidebar( 'blog-sidebar' ) ) : ?>
<ul>
<?php dynamic_sidebar( 'blog-sidebar' ); ?>
</ul>
<?php endif; // end blog widget area ?>
Wrap this code inside your divs in the sidebar and be sure you change the 'blog-sidebar' name to the one for each sidebar.

Looking for function admin_menu and edit in that line. Just replace __FILE__ by sidebar-generator.
Interpretation: If you use sidebar generator as a plugin, __FILE__ means sidebar-generator, but if you include it in some directory of your themes, the constant __FILE__ may change to something different (such as inc, includes... or something else)

Related

Custom taxonomy image for a single featured image product

I need to change all featured image products with the images of the term of taxonomy.
I tried this code and I have the right image taxonomy on a single page but does not replace the featured image of the product.
The name of my taxonomy is "settore"
Can you help me, please?
Have a great day
add_action("woocommerce_before_add_to_cart_form","product_taxonomy_image");
function product_taxonomy_image () {
print apply_filters( 'taxonomy-images-list-the-terms', '', array(
'before' => '<div class="my-custom-class-name">',
'after' => '</div>',
'before_image' => '<span>',
'after_image' => '</span>',
'image_size' => 'detail',
'taxonomy' => 'settore',
) );
}

CakePHP adding image to echo $this->Html->link

Hi I have tried various things but not sure if I am trying to over complicate things. Quite simply I want to add a small image country flag for the word 'Spanish' and 'English' and have an 'Alt' tag with those words instead. The following works fine with just text and as is but it would be cool to have the image either to replace or sit side by side with the word. Any help available?
echo $this->Html->link('Spanish', array('controller'=>'settings', 'action'=>'lang', 'spa'),
array('rel'=>'nofollow'));
}
else {
echo $this->Html->link('English', array('controller'=>'settings', 'action'=>'lang', 'eng'),
array('rel'=>'nofollow'));
}
You can either output just a linked image using the image method with a url attribute:-
<?php
echo $this->Html->image(
'spain.jpg',
array(
'alt' => 'Spanish',
'url' => array('controller' => 'settings', 'action' => 'lang', 'spa')
)
);
Or you can include an image with a text link by combining the normal CakePHP link method and the image method:-
<?php
echo $this->Html->link(
h('Spanish') . $this->Html->image('spain.jpg', array('alt' => 'Spanish')),
array('controller' => 'settings', 'action' => 'lang', 'spa'),
array('escape' => false, 'rel' => 'nofollow')
);
With the link method you need to remember to prevent Cake from escaping the img tag using 'escape' => false. If you disable escaping like this it is work remembering to escape any user provided text by using the h() method to prevent any HTML injection (I've shown this in my example wrapping the word 'Spanish' but this is only necessary if this is coming from a variable).
if you are using cake2 see this link to the cookbook
echo $this->Html->image("spain.jpg", array(
"alt" => "Spanish language",
'url' => array('controller' => 'settings', 'action' => 'lang', 'spa')
));

Yii vs Highcharts vs Ajax

here is a part of my view:
<?php
echo CHtml::dropDownList('al_ev_id', $model->al_ev_id,$listaDateAl,
array(
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('stat/ajaxStoricoSubDetails'),
'update'=>'#storicoSubDetails',
),
'class' => 'rowform',
));
...
?>
<div id="storicoSubdetails">
...
<?php
$this->Widget('ext.highcharts.HighchartsWidget', array(
'options'=>array(
'title' => array('text' => 'A title'),
'xAxis' => array(
'categories' => $model->streamLabel
),
'yAxis' => array(
'title' => array('text' => 'another title')
),
'series' => array(
array('name' => $model->labelGraph, 'data' => $model->streamData)
)
)
));
?>
...
</div>
the controller in the action 'ajaxStoricoSubDetails' reload the same $this->Widget('ext.highcharts.HighchartsWidget' etc, etc
the objective of this code is to update the starting x-value of the graph, modifying it with the dropdown
and here is my problem:
the first rendering of highcharts graph is ok; but, when I change the value in the DropDown, thus starting the ajax part, graph is not rendered
highcharts return an error 16 code, that means
Highcharts already defined in the page
in fact in the second rendering code (the ajax fired part) I find
<script src="http://code.highcharts.com/highcharts.js"></script>
that I think is the problem
is there any way to avoid this
Any other suggestions?
It's not the best long term solution, but...
If <script src="http://code.highcharts.com/highcharts.js"></script> is at the top of your page now, move it in <div id="storicoSubdetails"> instead.
That way the script reference should be overwritten when the ajax stuff reloads everything in the storicoSubdetails div, and you will only have 1 script reference on the page.

Codeigniter: creating helper with associative array

I have a number of social networking links (about 5) in the footer of my site and I need to generate data for each of the anchor link’s TITLE and URL - and ICON (image).
It’s not really worth creating a new table for only 5 rows, so I’m thinking a helper might be a the answer - some sort of associative array.
However, I’m a bit unsure how to construct the helper’s array - and completely clueless as to how to loop the results in the view file.
Any help, or any links to useful examples, is greatly appreciated!
In your helper:
function footer_link_data()
{
return array(
array(
'title' => 'Facebook',
'url' => 'http://facebook.com',
'icon' => 'http://placehold.it/64x64'
),
array(
'title' => 'Twitter',
'url' => 'http://twitter.com',
'icon' => 'http://placehold.it/64x64'
),
array(
'title' => 'Pinterest',
'url' => 'http://pinterest.com',
'icon' => 'http://placehold.it/64x64'
),
);
}
In your view:
<?php
$links = footer_link_data();
foreach($links as $link): ?>
<?php echo $link['icon'] ?>
<?php
endforeach; ?>
Alternatively, you can just create the HTML statically. For 5 links having it generated dynamically is kind of pointless.

How to translate form labels in Zend Framework 2?

I'm not getting it!.. Can please someone explain, how to translate form labels? A simple example would be great.
Thank you in advance!
class Search\Form\CourseSearchForm
...
class CourseSearchForm extends Form {
...
public function __construct(array $cities) {
parent::__construct('courseSearch');
...
$this->add(array(
'name' => 'city',
'type' => 'Zend\Form\Element\Select',
'options' => array(
'label' => 'Stadt',
'value_options' => $this->cities,
'id' => 'searchFormCity',
),
));
...
}
}
view script /module/Search/view/search/search/search-form.phtml
<?php echo $this->form()->openTag($form); ?>
<dl>
...
<dt><label><?php echo $form->get('city')->getLabel(); ?></label></dt>
<dd><?php echo $this->formRow($form->get('city'), null, false, false); ?></dd>
...
</dl>
<?php echo $this->form()->closeTag(); ?>
<!-- The formRow(...) is my MyNamespace\Form\View\Helper (extends Zend\Form\View\Helper\FormRow); the fourth argument of it disables the label. -->
The module/Application/config/module.config.php is configured:
return array(
'router' => ...
'service_manager' => array(
'factories' => array(
'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
),
),
'translator' => array(
'locale' => 'de_DE',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
),
'controllers' => ...
'view_manager' => ...
);
I also edited my view and use the FormLabel view helper:
<dt><label><?php echo $this->formLabel($form->get('city')); ?></label></dt>
Furthermore I debugged the FormLabel at the place, where the tranlator is used (lines 116-120) -- seems to be OK.
But it's still not working.
EDIT
The (test) items for labels, I added to the de_DE.po file manually, are tranlated. The ZF2 side problem was actually, that I was using $form->get('city')->getLabel() instead of $this->formlabel($form->get('city')) in th view script.
The problem is now, that the labels are not added to the de_DE.po file. But it's not a ZF2 issue anymore, so I've accept Ruben's answer and open a new Poedit question.
Instead of using:
<?php echo $form->get('city')->getLabel(); ?>
You should use the formlabel view helper. This helper automatically uses your translator during rendering if you have inserted it in your ServiceManager. Most likely you will have it in your Application's module module.config.php:
'service_manager' => array(
'factories' => array(
'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
),
),
'translator' => array(
'locale' => 'en_US',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
),
Once you do use the formlabel view helper:
echo $this->formLabel($form->get('city'));
And of course make sure your translations are in your .po file.
i think your problem is that you label are not detected by poedit (or similar tool), so you have to add them manually to your poedit catalogs (.po)
to make your label strings detected by tools like poedit, your strings need to be used inside a translate() function or _() (other function can be added in Catalog/properties/sources keyword)
as the _() function is not user in ZF2 (today) so a tiny hack is to add a function like this in your index.php (no need to modify anything, this way, in poedit params):
// in index.php
function _($str)
{
return $str;
}
and in your code, just use it when your strings are outside of a translate function
//...
$this->add(array(
'name' => 'city',
'type' => 'Zend\Form\Element\Select',
'options' => array(
'label' => _('myLabel') , // <------ will be detected by poedit
'value_options' => $this->cities,
'id' => 'searchFormCity',
),
));
//...
or like this if you prefer
$myLabel = _('any label string'); // <--- added to poedit catalog
//...
'options' => array(
'label' => $myLabel ,
'value_options' => $this->cities,
'id' => 'searchFormCity',
),
#Ruben says right!
Me I use PoEdit to generate my *.mo files and to be sure to get all translations in the file, I create somewhere (in view for example) a file named _lan.phtml with all text to be translated :
<?php echo $this->translate("My label");
... ?>
Of course, Poedit has to be configured to find my keywords. check this to how to configure it
All solutions don't use the power of ZF2. You must configure your poedit correctly :
All things are here :
http://circlical.com/blog/2013/11/5/localizing-your-twig-using-zend-framework-2-applications

Resources