How to use checkbox with wpalchemy - php

I have used following code to create a checkbox in WordPress pages (in admin section):
<?php while($mb->have_fields_and_multi('sidebar-block')): ?>
<?php $mb->the_group_open(); ?>
<!-- Some more code here for other fields -->
<p class="checkbox">
<input name="<?php $metabox->the_name('blue-block'); ?>" type="checkbox" value="1" <?php if ($metabox->get_the_value('blue-block')) echo ' checked="checked"'; ?>>
<label>Do not use Blue Block for content</label>
</p>
<?php $mb->the_group_close(); ?>
<?php endwhile; ?>
Above code is working fine. My question is how can i check if this checkbox is checked on the main website (frontend)?
Following is the code in my template for frontend:
<?php
$my_meta = get_post_meta($post->ID,'_sidebar_meta',TRUE);
if ($my_meta['sidebar-block']) {
foreach ($my_meta['sidebar-block'] as $sidebar)
{
?>
<div id="aside-blue">
<?php if ($sidebar['side_heading']) { ?>
<h2 class="sideheading"><?php echo $sidebar['side_heading']; ?></h2>
<?php } ?>
<?php echo apply_filters( 'the_content', $sidebar['side_content'] ); ?>
</div>
<?php } ?>
<?php } ?>
I want to add id="aside-blue" only when checkbox is checked.
i tried following code for this, but it's not working
<?php
$my_meta = get_post_meta($post->ID,'_sidebar_meta',TRUE);
if ($my_meta['sidebar-block']) {
foreach ($my_meta['sidebar-block'] as $sidebar)
{
?>
<div <?php if ($sidebar['blue-block'] == 'yes') { ?>id="aside-blue"<?php } ?>>
</div>
<?php } ?>
<?php } ?>

Check in the wp_postmeta table how the value is stored. When I used checkboxes, the values were serialized. You'll probably need to unserialize it before using the meta value.

Related

Fishpig Magento Integration

Because I am not a professional programmer, I can’t get the ACF integration up for the fishpig magento running.
Bought both the FishPig-ACF Add-on and the ACF Pro.
Installed both and made a custom field named “repeater” and as the autor describes in his manual, I added this code to the /post/view.phtml:
<?php $value = $post->getMetaValue('repeater') ?>
So my view.phtml looks like this:
<?php
/**
* #category Fishpig
* #package Fishpig_Wordpress
* #license http://fishpig.co.uk/license.txt
* #author Ben Tideswell <help#fishpig.co.uk>
*/
?>
<?php $post = $this->getPost() ?>
<?php if ($post): ?>
<?php $helper = $this->helper('wordpress') ?>
<?php $author = $post->getAuthor() ?>
<div class="page-title post-title">
<h1><?php echo $this->escapeHtml($post->getPostTitle()) ?></h1>
</div>
<div class="post-view">
<p class="post-date when"><?php echo stripslashes($this->__('This entry was posted on %s<span class=\"by-author\"> by %s</span>.', $post->getPostDate(), $post->getAuthor()->getDisplayName())) ?></p>
<?php echo $this->getBeforePostContentHtml() ?>
<?php $value = $post->getMetaValue('repeater') ?>
<div class="post-entry entry std<?php if ($post->getFeaturedImage()): ?> post-entry-with-image<?php endif; ?>">
<?php if ($post->isViewableForVisitor()): ?>
<?php if ($featuredImage = $post->getFeaturedImage()): ?>
<div class="featured-image left"><img src="<?php echo $featuredImage->getAvailableImage() ?>" alt="<?php echo $this->escapeHtml($post->getPostTitle()) ?>"/></div>
<?php endif; ?>
<?php echo $post->getPostContent() ?>
<?php else: ?>
<?php echo $this->getPasswordProtectHtml() ?>
<?php endif; ?>
</div>
<?php echo $this->getAfterPostContentHtml() ?>
<?php echo $this->getCommentsHtml() ?>
</div>
<?php endif; ?>
But in fronted the ACF is not shown.
THX for any help
You have copied and pasted the following code:
<?php $value = $post->getMetaValue('repeater') ?>
This code generates the repeater value and saves it in a variable named $value. That's it. This code doesn't do anything with this value or print it to the screen so the fact that nothing is displayed is correct.
To view what's inside the field, try the following:
<pre><?php print_r($post->getMetaValue('repeater')) ?></pre>
The above code will print out the value of the repeater field to the screen. Assuming you have set a value for this field for the current post, this value be an array containing the data that you set. You will then need to make use of foreach loops to cycle through the array and process/display the data.

How Can I Add Value to Save / Apply Changes with JToolBarHelper

I have an edit view which need to pass a hidden value through the form in a Joomla 2.5 component. Where would I go about adding this form value?
Here is my attempt (that is not working):
In the ../admin/models/forms/componentview.xml file I have added the following field:
<field
name="variableToPassBackToMainView"
type="hidden"
value="1"
/>
My thought was that by adding this hidden field to the model form, when it was saved then the variableToPassBackToMainView would be picked up by the new view. The view has the following variable definition to retrieve the value:
$variableToPassBackToMainView = $_REQUEST["variableToPassBackToMainView"];
Updated Info:
Joomla 2.5 Component
Here is the edit.php
<?php
defined('_JEXEC') or die('Restricted access');
JHtml::_('behavior.tooltip');
JHtml::_('behavior.formvalidation');
$params = $this->form->getFieldsets('params');
?>
<form action="<?php echo JRoute::_('index.php?option=com_mycomponent&layout=edit&id='.(int) $this->item->id); ?>" method="post" name="adminForm" id="mycomponent-form" class="form-validate">
<div class="width-60 fltlft">
<fieldset class="adminform">
<legend><?php echo JText::_( 'COM_MYCOMPONENT_DETAILS' ); ?></legend>
<ul class="adminformlist">
<?php foreach($this->form->getFieldset('componenttitledetails') as $field): ?>
<li><?php echo $field->label;echo $field->input;?></li>
<?php endforeach; ?>
</ul>
</div>
<div class="width-40 fltrt">
<?php echo JHtml::_('sliders.start', 'mycomponent-slider'); ?>
<?php foreach ($params as $name => $fieldset): ?>
<?php echo JHtml::_('sliders.panel', JText::_($fieldset->label), $name.'-params');?>
<?php if (isset($fieldset->description) && trim($fieldset->description)): ?>
<p class="tip"><?php echo $this->escape(JText::_($fieldset->description));?></p>
<?php endif;?>
<fieldset class="panelform" >
<ul class="adminformlist">
<?php foreach ($this->form->getFieldset($name) as $field) : ?>
<li><?php echo $field->label; ?><?php echo $field->input; ?></li>
<?php endforeach; ?>
</ul>
</fieldset>
<?php endforeach; ?>
<?php echo JHtml::_('sliders.end'); ?>
</div>
<div>
<input type="hidden" name="task" value="componentview.edit" />
<?php echo JHtml::_('form.token'); ?>
</div>
</form>

I want to get value from fields loop .How can I do?

I'm using joomla and I have begun to develop a web app, I want to get values from form fields. Normally I use $_POST but this page didn't work.
This is my default.php >>>
<?php
defined('_JEXEC') or die;
JHtml::_('behavior.keepalive');
JHtml::_('behavior.tooltip');
JHtml::_('behavior.formvalidation');
?>
<div class="item" <?php echo $this->pageclass_sfx?>">
<?php if ($this->params->get('show_page_heading')) : ?>
<h1><?php echo $this->escape($this->params->get('page_heading')); ?></h1>
<?php endif; ?>
<form id="add-item" action="<?php echo JRoute::_('index.php?option=com_stationery&task=item.save'); ?>" method="post" class="form-validate" enctype="multipart/form-data">
<?php foreach ($this->form->getFieldsets() as $fieldset): // Iterate through the form fieldsets and display each one.?>
<?php $fields = $this->form->getFieldset($fieldset->name);?>
<?php if (count($fields)):?>
<fieldset>
<?php if (isset($fieldset->label)):// If the fieldset has a label set, display it as the legend.
?>
<legend><?php echo JText::_($fieldset->label);?></legend>
<?php endif;?>
<dl>
<?php foreach($fields as $field):// Iterate through the fields in the set and display them.?>
<?php if ($field->hidden):// If the field is hidden, just display the input.?>
<?php echo $field->input;?>
<?php else:?>
<dt>
<?php echo $field->label; // Show label for registor ?>
<?php if (!$field->required && $field->type!='Spacer'): ?>
<?php endif; ?>
</dt>
<dd><?php echo ($field->type!='Spacer') ? $field->input : " "; ?></dd>
<?php endif;?>
<?php endforeach;?>
</dl>
</fieldset>
<?php endif;?>
<?php endforeach;?>
<div>
<button name="save" type="submit" class="btn btn-success" class="validate"><?php echo JText::_('Save');?></button>
<?php echo JText::_('or');?>
<a class="btn btn-danger" href="<?php echo JRoute::_('/stationery/index.php/add-items');?>" title="<?php echo JText::_('JCANCEL');?>"><?php echo JText::_('JCANCEL');?></a>
<input type="hidden" name="option" value="com_stationery" />
<input type="hidden" name="task" value="item.save" />
<?php echo JHtml::_('form.token');?>
</div>
</form>
<script>
This is loop from field.xml to show each field. I want to get value in that inputbox. now I can get to javascript variable but I can't use to save in my table. I want php variable ($....). How can I get it? Please help me. Thank you
In Joomla 2.5+ you could use JRequest, but since it's deprecated you should:
JFactory::getApplication()->input->get...
however looking at your code there may be a simpler approach just bind the input to the table model

php multiple if's but not related

I have a WP site but this is a PHP question, I have the following code:
f(!empty($c_dates1_new)) { ?>
<p class="text">Dates: From <?php echo $c_dates1_new; ?> to <?php echo $c_datee1_new; ?></p>
<?php } if(!empty($c_dates2_new)) { ?>
<p class="text">Dates 2: From <?php echo $c_dates2_new; ?> to <?php echo $c_datee2_new; ?></p>
<?php } if(!empty($c_dates3_new)) { ?>
<p class="text">Dates 3: From <?php echo $c_dates3_new; ?> to <?php echo $c_datee3_new; ?></p>
<?php } if(!empty($c_dates4_new)) { ?>
<p class="text">Dates 4: From <?php echo $c_dates4_new; ?> to <?php echo $c_datee4_new; ?></p>
<?php }
Now this only shows the content from $c_dates_1 where it should display the content from all of them.
I cannot workout what I need to put between them e.g. it's not an else, it's not an OR and it's not an AND as they are all separate checks, not related to each other.
any input is appreciated

If statment to only show one value from an array

I am using onestepcheckout in Magento. I have added in some extra flat rates and I am using two of them. I want to be able to only show one of the flat rates depending on the subtotal of the cart.
I have got the subtotal into a variable but the code has a foreach through each shipping method available so I need a way to say if $total is over 500 only show the second shipping method, if the total is under 500 only show the first shipping method.
<?php $total = Mage::getSingleton('checkout/session')->getQuote()->getSubtotal(); ?>
<?php foreach ($_shippingRateGroups as $code => $_rates): ?>
<dd><?php echo $this->getCarrierName($code) ?></dd>
<?php foreach ($_rates as $_rate): ?>
<dt style="margin-bottom: 5px;">
<?php if ($_rate->getErrorMessage()): ?>
<ul class="messages"><li class="error-msg"><ul><li><?php echo $_rate->getErrorMessage() ?></li></ul></li></ul>
<?php else: ?>
<input name="shipping_method" type="radio" class="validate-one-required-by-name" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> />
<label for="s_method_<?php echo $_rate->getCode() ?>"><!--<b><?php echo $this->getCarrierName($code) ?>:</b>--> <?php echo $_rate->getMethodTitle() ?>
<strong>
<?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
<?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
<?php echo $_excl; ?>
<?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
(<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
<?php endif; ?>
</strong>
</label>
<?php endif ?>
</dt>
<?php endforeach; ?>
<?php endforeach; ?>
Just do ...
//first method here by default
if($total>500){
//second method here
}
Something tells me you already know how to do this though
I can't decipher, what the first and second method are in your code, otherwise I would've posted a more complete code

Categories