Call for the wordpress text field - php

I am working in an existing theme from my company. They have a special page template. This template uses custom fields you can fill in, they then get displayed on the page.
The general text field that you see when editing a page is not shown on the page however. (it is in the dashboard environment.) This is what the page template looks like:
<?php get_header() ?>
<?php the_post() ?>
<!-- start content -->
<div id="content">
<div class="col left">
<?php dynamic_sidebar( 'left-widgets' ); ?>
</div>
<h1 class="mobiletitle" style="text-align:center;"><?php the_title() ?> </h1>
<div id="center">
<div class="two-col">
<?php
if( get_field('slider') )
{ ?>
<div class="rslides_container">
<ul class="rslides" id="slider1">
<?php while( has_sub_field("slider") )
{
$variable = get_sub_field('image'); ?>
<li><img src="<?php echo $variable;?>" alt="Magic Stables"></li>
<?php } ?>
</ul>
</div>
<?php } ?>
<h1 class="maintitle" style="text-align:center;"><?php the_title() ?> </h1>
<div class="horseinfo">
<table>
<?php if(get_field('naam_paard')) { ?>
<tr>
<td><?php if(ICL_LANGUAGE_CODE=='nl') { ?>
Naam:
<?php } else { ?>
Name:
<?php } ?></td>
<td><?php the_field('naam_paard'); ?></td>
</tr>
<?php } ?>
<?php if(get_field('afstamming')) { ?>
<tr>
<td><?php if(ICL_LANGUAGE_CODE=='nl') { ?>
Afstamming:
<?php } else { ?>
Breed:
<?php } ?></td>
<td><?php the_field('afstamming'); ?></td>
</tr>
<?php } ?>
<?php if(get_field('geslacht')) { ?>
<tr>
<td><?php if(ICL_LANGUAGE_CODE=='nl') { ?>
Geslacht:
<?php } else { ?>
Gender:
<?php } ?></td>
<td><?php the_field('geslacht'); ?></td>
</tr>
<?php } ?>
<?php if(get_field('geboortejaar')) { ?>
<tr>
<td><?php if(ICL_LANGUAGE_CODE=='nl') { ?>
Geboortejaar:
<?php } else { ?>
Year of Birth:
<?php } ?></td>
<td><?php the_field('geboortejaar'); ?></td>
</tr>
<?php } ?>
<?php if(get_field('geboortejaarkleur')) { ?>
<tr>
<td><?php if(ICL_LANGUAGE_CODE=='nl') { ?>
Geboortejaarkleur:
<?php } else { ?>
Birth color:
<?php } ?></td>
<td><?php the_field('geboortejaarkleur'); ?></td>
</tr>
<?php } ?>
<?php if(get_field('stokmaat')) { ?>
<tr>
<td><?php if(ICL_LANGUAGE_CODE=='nl') { ?>
Stokmaat:
<?php } else { ?>
Height:
<?php } ?></td>
<td><?php the_field('stokmaat'); ?></td>
</tr>
<?php } ?>
<?php if(get_field('fokker_naam')) { ?>
<tr>
<td><?php if(ICL_LANGUAGE_CODE=='nl') { ?>
Fokker:
<?php } else { ?>
Breeder:
<?php } ?></td>
<td><?php the_field('fokker_naam'); ?></td>
</tr>
<?php } ?>
<?php if(get_field('fokker_plaats')) { ?>
<tr>
<td><?php if(ICL_LANGUAGE_CODE=='nl') { ?>
Fokker plaats:
<?php } else { ?>
Breeding place:
<?php } ?></td>
<td><?php the_field('fokker_plaats'); ?></td>
</tr>
<?php } ?>
<?php if(get_field('overig')) { ?>
<tr>
<td><?php if(ICL_LANGUAGE_CODE=='nl') { ?>
Overig:
<?php } else { ?>
Other:
<?php } ?></td>
<td><?php the_field('overig'); ?></td>
</tr>
<?php } ?>
</table>
</div>
<br><br>
<?php if(the_content()) { ?>
<div class="one-col">
<?php the_content() ?>
</div>
<?php } ?>
<?php if(get_field('linkerkolom')) { ?>
<div class="two-col-1">
<?php the_field('linkerkolom'); ?>
</div>
<div class="two-col-2">
<?php the_field('rechterkolom'); ?>
</div>
<?php } ?>
</div>
</div>
<div class="col right">
<?php dynamic_sidebar( 'right-widgets' ); ?>
</div>
<?php get_footer() ?>
I see that with this line you make the text from a custom form appear:
<?php the_field('fokker_naam'); ?>
Now, how do I get the normal field to appear on the page again? What is the name of this field?
I need to use this field because I would like to use the editor, to create font styles and such.

The main post content is accessed via the_content() function:
<?php the_content(); ?>

Related

How to use if elseif inside table row without making a new row?

I want to make a code that can use if else if inside table row.
But I can't make it ,once I use else if statement inside table row it make a new row by it self.
I expect that it make a new column in the same row
Here's a code
<tbody>
<?php $i = 1;
$varpetugas = null;
$varrealisasi = null;
?>
<?php foreach ($petugas as $k) : ?>
<tr>
<?php if ($k['nama_petugas'] != $varpetugas) : ?>
<th scope="row"><?= $i++; ?></th>
<td><?= $k['jenis_survey']; ?></td>
<td>
<?= $k['nama_petugas']; ?>
<?php $varpetugas = $k['nama_petugas']; ?></td>
<td><?= $k['target']; ?></td>
<td><?= $k['realisasi']; ?></td>
<?php $varrealisasi = $k['realisasi']; ?>
<?php elseif ($k['nama_petugas'] == $varpetugas) : ?>
<td>
<?= $k['target']; ?>
</td>
<td>
<?= $k['realisasi']; ?>
</td>
<?php $varrealisasi = $k['realisasi']; ?>
<?php $varpetugas = $k['nama_petugas']; ?>
<?php endif; ?>
</tr>
<?php endforeach; ?>
</tbody>
as you can see what I expected is else if statement show the output in a same row but , here's the result
You do new row (<tr>) every time when loop (next line after foreach).
But what you want to do is to have it only when condition (<?php if ($k['nama_petugas'] != $varpetugas) : ?>) is true.
Try this:
<?php foreach ($petugas as $k) : ?>
<?php if ($k['nama_petugas'] != $varpetugas) : ?>
<?php if ($i > 1) : ?>
</tr>
<?php endif; ?>
<tr>
<th scope="row"><?= $i++; ?></th>
<td><?= $k['jenis_survey']; ?></td>
<td>
<?= $k['nama_petugas']; ?>
<?php $varpetugas = $k['nama_petugas']; ?></td>
<td><?= $k['target']; ?></td>
<td><?= $k['realisasi']; ?></td>
<?php $varrealisasi = $k['realisasi']; ?>
<?php elseif ($k['nama_petugas'] == $varpetugas) : ?>
<td>
<?= $k['target']; ?>
</td>
<td>
<?= $k['realisasi']; ?>
</td>
<?php $varrealisasi = $k['realisasi']; ?>
<?php $varpetugas = $k['nama_petugas']; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php if ($i > 1) : ?>
</tr>
<?php endif; ?>
PS: Why do you have elseif? You can simply do just else. Isn't it?

How to simplify if statement into loop

I'm currently doing this if statement here, I wanted to simplify it into a loop. I try putting it into an array for the client_fullname and etc. but turns out only string form can be done. I wanted to simplicity this coding into a loop but i have no idea how to do it.
<tr class="sale" data-id="<?= $sale['id']; ?>">
<td><?= $pagination->offset + $key + 1; ?></td>
<?php if ($checked_columns['client_fullname']): ?>
<td><?= $sale['client_fullname']; ?></td>
<?php endif; ?>
<?php if ($checked_columns['client_email']): ?>
<td> <?php echo $sale['client_email']; ?></td>
<?php endif; ?>
<?php if ($checked_columns['client_phone_number']): ?>
<td> <?php echo $sale['client_phone_number']; ?></td>
<?php endif; ?>
<?php if ($checked_columns['total_amount']): ?>
<td><?= $sale['total_amount']; ?></td>
<?php endif; ?>
<?php if ($checked_columns['total_sales_amount']): ?>
<td><?= $sale['total_sales_amount']; ?></td>
<?php endif; ?>
<?php if ($checked_columns['first_date_buy']): ?>
<td><?= $sale['first_date_buy']; ?></td>
<?php endif; ?>
<?php if ($checked_columns['created_at']): ?>
<td><?= $sale['created_at']; ?></td>
<?php endif ?>
</tr>
You can reference the below example to achieve your desired output.
<?php
foreach($checked_columns as $key=>$column){
if ($column){
if ($key == 'client_email' || $key == 'client_phone_number'){?>
<td> <?= $sale[$key]; ?></td>
<?php }else{?>
<td><?= $sale[$key]; ?></td><?php
}
}

Magento customer dashboard tracking number

I'm editing the template file for the customer dashboard at sales/order/recent.phtml. I want the tracking number along with a tracking link to show up under the recent order. I have tried the following but getAllTracks is not grabbing anything. Thoughts?
<?php foreach ($_orders as $_order): ?>
<tr>
<td><?php echo $_order->getRealOrderId() ?></td>
<td><span class="nobr"><?php echo $this->formatDate($_order->getCreatedAtStoreDate()) ?></span></td>
<td><?php echo $_order->getShippingAddress() ? $this->htmlEscape($_order->getShippingAddress()->getName()) : ' ' ?></td>
<td><?php echo $_order->formatPrice($_order->getGrandTotal()) ?></td>
<td><em><?php echo $_order->getStatusLabel() ?></em></td>
<td class="a-center">
<span class="nobr">
<?php echo $this->__('View Order') ?>
<?php if ($this->helper('sales/reorder')->canReorder($_order)) : ?>
<span class="separator">|</span> <?php echo $this->__('Reorder') ?>
<?php endif ?>
</span>
</td>
</tr>
<tr>
<?php $collection = Mage::getResourceModel('sales/order_shipment_collection');
$collection->addAttributeToFilter('order_id', $_order->getRealOrderId()); ?>
<?php foreach($collection as $_ship): ?>
<?php var_dump($_ship->getAllTracks())?>
<?php $i=0; foreach ($_ship->getAllTracks() as $_item): $i++ ?>
<?php $url = $this->helper('shipping')->getTrackingPopupUrlBySalesModel($_order) ?>
<?php echo "URL is". $url ?>
<?php if ($url): ?>
<td align="center" valign="top" style="padding:3px 9px"><?php echo $_item->getNumber() ?></td>
<?php else: ?>
<td align="center" valign="top" style="padding:3px 9px"><?php echo $_item->getNumber() ?></td>
<?php endif; ?>
<?php endforeach ?>
<!---Track --->
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
Ended up being a really short line of code to put the link in there. I didn't bother to keep working at getting the tracking number. I put the link in the second to last column.
<div class="box-account box-recent">
<?php $_orders = $this->getOrders(); ?>
<div class="box-head">
<h2><?php echo $this->__('Recent Orders') ?></h2>
<?php if( sizeof($_orders->getItems()) > 0 ): ?><?php echo $this->__('View All') ?><?php endif; ?>
</div>
<?php if( sizeof($_orders->getItems()) > 0 ): ?>
<table class="data-table" id="my-orders-table">
<col width="1" />
<col width="1" />
<col />
<col width="1" />
<col width="1" />
<col width="1" />
<thead>
<tr>
<th><?php echo $this->__('Order #') ?></th>
<th><?php echo $this->__('Date') ?></th>
<th><?php echo $this->__('Ship To') ?></th>
<th><span class="nobr"><?php echo $this->__('Order Total') ?></span></th>
<th><?php echo $this->__('Status') ?></th>
<th><?php echo $this->__('Track') ?></th>
<th> </th>
</tr>
</thead>
<tbody>
<?php foreach ($_orders as $_order): ?>
<tr>
<td><?php echo $_order->getRealOrderId() ?></td>
<td><span class="nobr"><?php echo $this->formatDate($_order->getCreatedAtStoreDate()) ?></span></td>
<td><?php echo $_order->getShippingAddress() ? $this->htmlEscape($_order->getShippingAddress()->getName()) : ' ' ?></td>
<td><?php echo $_order->formatPrice($_order->getGrandTotal()) ?></td>
<td><em><?php echo $_order->getStatusLabel() ?></em></td>
<td>
<?php if ($_order->getTracksCollection()->count()) : ?>
<?php echo $this->__('Track Order Shipment') ?>
<br/>
<?php endif; ?>
</td>
<td class="a-center">
<span class="nobr">
<?php echo $this->__('View Order') ?>
<?php if ($this->helper('sales/reorder')->canReorder($_order)) : ?>
<span class="separator">|</span> <?php echo $this->__('Reorder') ?>
<?php endif ?>
</span>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<script type="text/javascript">decorateTable('my-orders-table')</script>
<?php else: ?>
<p><?php echo $this->__('You have placed no orders.'); ?></p>
<?php endif; ?>
</div>

Yii form fields rendered twice

The fields of my yii form in the register page are rendered twice!!
can anybody pls help me find out what's causing this?
here is the code from the controller:
public function actionRegister()
{
$form=new Users;
// collect user input data
if(isset($_POST['Users']))
{
$form->attributes=$_POST['Users']; // set all attributes with post
// NOTE Changes to any $form->value have to be performed BEFORE $form-validate()
// or else it won't save to the database.
// validate user input and redirect to previous page if valid
if($form->validate())
{
// save user registration
$form->save();
$this->redirect(Yii::app()->createUrl('site/login'));
}
}
// display the registration form
$this->render('register',array('form'=>$form));
}
here is the code from the view:
<?php $pagetitle = "Hubylon | Register"; ?>
<?php $this->breadcrumbs=array('Register'); ?>
<div class="yiiForm">
<?php echo CHtml::beginForm(); ?>
<?php echo CHtml::errorSummary($form); ?>
<div class="row">
<table>
<tr>
<td>*<?php echo CHtml::activeLabel($form,'username'); ?>:</td>
<td><?php echo CHtml::activeTextField($form,'username'); ?></td>
<td><?php echo CHtml::error($form,'username',array('style' => 'color:red;font-size:11px;')); ?></td>
</tr>
</table>
</div>
<div class="row">
<table>
<tr>
<td>*<?php echo CHtml::activeLabel($form,'password'); ?>:</td>
<td><?php echo CHtml::activePasswordField($form,'password'); ?></td>
<td><?php echo CHtml::error($form,'password',array('style' => 'color:red;font-size:11px;')); ?></td>
</tr>
</table>
</div>
<div class="row">
<table>
<tr>
<td>*<?php echo CHtml::activeLabel($form,'confirmPassword'); ?>:</td>
<td><?php echo CHtml::activePasswordField($form,'confirmPassword'); ?></td>
<td><?php echo CHtml::error($form,'confirmPassword',array('style' => 'color:red;font-size:11px;')); ?></td>
</tr>
</table>
</div>
<div class="row">
<table>
<tr>
<td><?php echo CHtml::activeLabel($form,'first_name'); ?>:</td>
<td><?php echo CHtml::activeTextField($form,'first_name'); ?></td>
<td><?php echo CHtml::error($form,'first_name',array('style' => 'color:red;font-size:11px;')); ?></td>
</tr>
</table>
</div>
<div class="row">
<table>
<tr>
<td><?php echo CHtml::activeLabel($form,'birthdate'); ?>:</td>
<td><?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'attribute'=>'birthdate',
'model' => $form,
//'language'=>Yii::app()->language=='en' ? 'en' : null,
'options'=>array(
'dateFormat'=>'yy-mm-dd',
'defaultDate'=>$form->birthdate,
'buttonImage'=>Yii::app()->baseUrl.'/images/icons.date.png',
'buttomImageOnly'=>true,
'showAnim'=>'fold',
'showOn'=>'button',
'yearRange'=>'1900',),
'htmlOptions'=>array(
'style'=>'width:80px;vertical-align:top'
),
));
?></td>
</tr>
</table>
</div>
<div class="action">
<?php echo CHtml::submitButton('Register'); ?>
</div>
<?php echo CHtml::endForm(); ?>
thanks!
seems there's no problem from the code you have given,
but maybe you can checkout the layouts and the init() method of the current controller.
i managed to resolve it by adding the following line before the render:
$this->layout = '//layouts/login';
thanks!

Need Help with inserting code

I am not a programmer by no means. I am trying to figure out how to get this code inserted into profile.php
$author_id = get_query_var('author');
if($author_id){
echo do_shortcode("[photosmash gallery_type='contributor' author=" . $author_id . " no_form=true]");
}
Below is profile.php code:
<?php global $mngl_user, $mngl_friend, $mngl_options; ?>
<?php $display_profile = ( $user->privacy == 'public' or
MnglUser::is_logged_in_and_an_admin() or
MnglUser::is_logged_in_and_visible() ); ?>
<table class="mngl-profile-table">
<tr>
<td valign="top" class="mngl-profile-table-col-1 mngl-valign-top">
<table>
<tr>
<td>
<?php echo $avatar; ?>
<?php echo $mngl_friends_controller->display_add_friend_button($mngl_user->id, $user->id); ?>
<?php echo do_action('mngl-profile-display',$user->id); ?>
</td>
</tr>
<tr>
<td valign="top" class="mngl-valign-top">
<?php if($display_profile) { ?>
<?php if(isset($mngl_options->field_visibilities['profile_front']['bio']) and !empty($user->bio)) { ?>
<p class="mngl-profile-bio"><?php echo MnglBoardsHelper::format_message($user->bio); ?></p>
<?php } ?>
<div class="mngl-profile-information">
<?php if(isset($mngl_options->field_visibilities['profile_front']['name']) and !empty($user->first_name) and ($user->first_name != $user->screenname)) { ?>
<p class="mngl-profile-field"><strong><?php _e('Name', 'mingle'); ?>:</strong><br/><?php echo wptexturize(stripslashes($user->first_name)); ?>
<?php if(!empty($user->last_name)){ ?>
<?php echo " " . wptexturize(stripslashes($user->last_name)); ?>
<?php } ?>
</p>
<?php } ?>
<?php if(isset($mngl_options->field_visibilities['profile_front']['sex']) and !empty($user->sex)) { ?>
<p class="mngl-profile-sex"><strong><?php _e('Gender', 'mingle'); ?>:</strong><br/><?php echo $user->sex_display; ?></p>
<?php } ?>
<?php if(isset($mngl_options->field_visibilities['profile_front']['location']) and !empty($user->location)) { ?>
<p class="mngl-profile-location"><strong><?php _e('Location', 'mingle'); ?>:</strong><br/><?php echo wptexturize($user->location); ?></p>
<?php } ?>
<?php if(isset($mngl_options->field_visibilities['profile_front']['birthday']) and !empty($user->birthday)) { ?>
<p class="mngl-profile-location"><strong><?php _e('Birthday', 'mingle'); ?>:</strong><br/><?php echo wptexturize($user->birthday); ?></p>
<?php } ?>
<?php if(isset($mngl_options->field_visibilities['profile_front']['url']) and !empty($user->url)) { ?>
<p class="mngl-profile-url"><strong><?php _e('Website', 'mingle'); ?>:</strong><br/><?php echo make_clickable($user->url); ?></p>
<?php } ?>
</div>
<?php } ?>
<p><strong><?php _e('Friends', 'mingle'); ?>:</strong><div class="mngl-profile-friend-grid-wrap"><?php echo $mngl_friends_controller->display_friends_grid($user->id); ?></div></p>
</td>
</tr>
</table>
</td>
<td valign="top" class="mngl-profile-table-col-2">
<table class="mngl-profile-body">
<tr>
<td>
<div class="mngl-profile-name"><?php echo $user->screenname; ?></div>
<?php
if(!$display_profile)
require( MNGL_VIEWS_PATH . '/mngl-boards/private.php' );
?>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<?php if($display_profile) { ?>
<td valign="top" width="100%"><div class="mngl-board"><?php echo $mngl_boards_controller->display($user->id); ?></div></td>
<?php } ?>
</tr>
</table>
</td>
</table>
The new code needs to be enclosed in <?php and ?>. Then insert it into any free HTML area, for example between the empty <td> and </td> at the bottom. If it looks better elsewhere, move it. For non-programmers this is a trial end error method. Just take care not to insert it within any <?php if(... and <?php } ?> areas.

Categories