I have a customizer section inside my wordpress theme. I made a setting and a control for an icon. I want my user to be able to choose what icon he wants. I implemented the icomoon icon font with classes like icon-home.
I made a setting and a control for that icon like this:
$wp_customize->add_setting(
'service1_icon',
array(
'default' => 'icon1',
'type' => 'option',
)
);
$wp_customize->add_control(
'service1_icon',
array(
'label' => 'Service 1 Icon',
'section' => 'section_services',
'type' => 'select',
'choices' => array(
'icon1' => 'mobile',
'icon2' => 'home',
),
)
);
and in html/php:
<span class="service-icon icon-<?php echo get_theme_mod('service1_icon', 'icon1'); ?>"></span>
But when in my browser I see the output like this:
<span class="service-icon icon-icon1"></span>
instead of:
<span class="service-icon icon-mobile"></span>
I was trying to fix it and did some stuff that were illogical to me and I fixed it.
First, I removed the type from the setting:
$wp_customize->add_setting(
'service1_icon',
array(
'default' => 'icon1',
)
);
Then I renamed icon1, icon2... to the actual name of the icon:
$wp_customize->add_control(
'service1_icon',
array(
'label' => 'Service 1 Icon',
'section' => 'section_services',
'type' => 'select',
'choices' => array(
'mobile' => 'mobile',
'home' => 'home',
),
)
);
Related
I'm so beginner in Prestashop 1.7, I wanted to add a dropdown select section in my banner module to select the way to open the banner link.
but the selected value is never passed to the HTML, the code below IS passed but the one under isn't, can you please assist me?
[enter image description here][1]
array(
'type' => 'text',
'lang' => true,
'label' => $this->trans('Banner description', array(), 'Modules.Banner.Admin'),
'name' => 'BANNER_DESC',
'desc' => $this->trans('Please enter a short but meaningful description for the banner.', array(), 'Modules.Banner.Admin')
)
array(
'type' => 'select', //select
'lang' => true,
'label' => $this->trans('Banner tab', array(), 'Modules.Banner.Admin'),
'name' => 'BANNER_TAB',
'required'=>'true',
'options' => array(
'query' => array(
array('key' => '_blank', 'name' => 'New tab'),
array('key' => '_self', 'name' => 'Same tab'),
),
'id' => 'key',
'name' => 'name'
),
'desc' => $this->trans('Please select the way to open the link.', array(), 'Modules.Banner.Admin')
)
This is how it looks in the Backoffice:
Here
You not only need to add a new field to your form but also handle saving the data from it.
Take a look at a few examples:
https://github.com/PrestaShop/ps_featuredproducts/blob/dev/ps_featuredproducts.php#L122
Notice how the module author managed to save each configuration field from the form. This is what you need to do.
If you want to have access to data in your view, you have to pass it:
https://github.com/PrestaShop/ps_featuredproducts/blob/dev/ps_featuredproducts.php#L244
Maybe after you added a new field, you forgot to handle the saving + passing to the view?
Is it possible to put a maxlength on the input fields i use in the customizer.
Like putting some extra setting in the array : maxlength = > 50;
via :
$wp_customize->add_control( 'textblock-text-content', array(
'label' => 'Tekstblok tekst',
'section' => 'textblock_background_section',
'type' => 'textarea',
));
I couldnt find any solution, i hope anybody here can guide me to a fix.
Accoding to Customizer Objects docs, you could use the input_attrs parameter like this:
$wp_customize->add_control('textblock-text-content', array(
'label' => 'Tekstblok tekst',
'section' => 'textblock_background_section',
'type' => 'textarea',
'input_attrs' => array(
'maxlength' => 20
)
));
So I have the following code:
add_action('customize_register', 'homepage_sections');
//products
function homepage_sections($wp_customize){
$wp_customize->add_panel('homepage_sections', array(
'title' => 'Homepage Sections',
'priority' => '20'
));
$wp_customize->add_section('homepage_settings_section', array(
'title' => 'Homepage settings',
'panel' => 'homepage_sections',
));
$wp_customize->add_setting('homepage_settings_setting', array(
'default' => 1
));
$wp_customize->add_control('homepage_settings_control', array(
'section' => 'homepage_settings_section',
'settings' => 'homepage_settings_setting',
'label' => 'Number of sections',
'description' => 'Number of sections in homepage',
'type' => 'number'
));
global $wpdb;
$sections=$wpdb->get_results('SELECT section_id, section_title FROM vt_homepage_sections;');
foreach($sections as $key){
$section_id=$key->section_id;
$cust_setting_id=$section_id.'_setting';
$cust_control_id=$section_id.'_control';
$wp_customize->add_setting($cust_setting_id,array(
));
$wp_customize->add_control($cust_control_id,array(
'settings' => $cust_setting_id,
'section' => 'homepage_settings_section',
'label' => 'test Control'
));
}
}
Issue
Everything works fine when i don't use variables which contain a value fetched using $wpdb. Is $wpdb object loaded after customizer framework?
When I use the code above, the above customized objects font appear in the customizer panel. Would appreciate hints to what's wrong with my code above.
Thanks in advance,
J
Please try this like this '$sections = $wpdb->get_results('SELECT section_id, section_title FROM vt_homepage_sections');'
define global class at the start of function and check.
I have a custom admin page in prestashop and i would like to add a URL link at the bottom of that page. However, i am very new to prestashop and can not figure out how to do this.
I have an admin controller file for the module that creates the custom page with a form on it and was wondering how i can add a link at the bottom of the page that simply goes to another static page on the site or even an external page.
AdminFedeltaSchoolsController.php content
<?php
class AdminFedeltaSchoolsController extends ModuleAdminController {
public function __construct() {
// Configure admin controller with table, model, language and bootstrap theme
$this->table = 'fedeltapos_school';
$this->className = 'FedeltaposModel';
$this->lang = true;
$this->bootstrap = true;
// Generat action on list
$this->addRowAction('edit');
$this->addRowAction('delete');
// This adds a multiple deletion button
$this->bulk_actions = array(
'delete' => array(
'text' => $this->l('Delete selected'),
'confirm' => $this->l('Delete selected items?')
)
);
// Generat list
$this->fields_list = array(
'id_fedeltapos_school' => array(
'title' => $this->l('ID'),
'align' => 'center',
'width' => 25
),
'school_name' => array(
'title' => $this->l('School Name'),
'width' => 'auto'
),
'delivery' => array(
'title' => $this->l('Delivery'),
'width' => 'auto'
),
'pickup' => array(
'title' => $this->l('Pickup'),
'width' => 'auto'
),
'pricelevel' => array(
'title' => $this->l('Price Level'),
'width' => 'auto',
),
);
parent::__construct();
}
// This method generates the Add/Edit form
public function renderForm() {
// Building the Add/Edit form
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Schools'),
'icon' => 'icon-envelope-alt'
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('School Name:'),
'name' => 'school_name',
'lang' => true,
'size' => 33,
'required' => true,
), array(
'type' => 'text',
'label' => $this->l('Delivery:'),
'name' => 'delivery',
'size' => 33,
'required' => true,
),
array(
'type' => 'text',
'label' => $this->l('Pickup:'),
'name' => 'pickup',
'size' => 33,
'required' => true,
),
array(
'type' => 'text',
'label' => $this->l('Price Level:'),
'name' => 'pricelevel',
'size' => 33,
'required' => true,
),
),
'submit' => array(
'title' => $this->l('Save')
)
);
return parent::renderForm();
}
}
I would like the link at the bottom of the page (see screenshot):
http://awesomescreenshot.com/08252wdh8a
Any assistance will be appreciated.
Override the default content admin template file of your admin controller.
Create /your-admin-folder/themes/default/template/controllers/fedelta_schools/content.tpl
{if isset($content)}
{$content}
{/if}
{block name="override_tpl_schools"}
<div class="row">
<div class="col-lg-12">
<div class="panel">
<h3>
<i class="icon-info"></i>
{l s='Help'}
</h3>
<p>{l s='You can find answer of your question here :'} <a href='#'>{l s='FAQ'}</a> </p>
</div>
</div>
</div>
{/block}
So I have an PHP file that includes a form so that users can post jobs on my website. I want to make some fields of this form ReadOnly to the user. How?
public static function init_fields() {
if ( self::$fields )
return;
self::$fields = apply_filters( 'submit_job_form_fields', array(
'job' => array(
'job_category' => array(
'label' => __( 'Job category', 'job_manager' ),
'type' => 'select',
'required' => true,
'options' => self::job_categories(),
'placeholder' => '',
'priority' => 3
),
'job_description' => array(
'label' => __( 'Description', 'job_manager' ),
'type' => 'text',
'required' => true,
'placeholder' => '',
'priority' => 4
),
I know this is probably easy to do, but for some reason I can't find how to do it.
Use the disabled attribute:
'job_description' => array(
'label' => __( 'Description', 'job_manager' ),
'type' => 'text',
'required' => true,
'placeholder' => '',
'priority' => 4,
'disabled' => 'true' //html disabled input
)
This is a proprietary config file. You need to look at the code that is parsing it and converting to HTML. It may allow passing through variables like readonly, or may not.
Try passing 'readonly' => true in your array.
Remember that someone can change the value of the readonly field using an inspector like Firebug, Chrome Developer Tools, etc.