I am trying to get the ACF checkbox to output an image when when it is checked. Here is what I have
<?php if (in_arry('The Home Depot', ("retailers"))) {
echo '<img src="' . echo get_stylesheet dirctory_url() . '/images/thehomedepot.jpg'" alt="The Home Depot">
} elseif(in_arry('True Value', ("retailers"))) {
echo '<img src="' . echo get_stylesheet dirctory_url() . '/images/truevalue.jpg'" alt="The Home Depot">
}else {
}
?>
retailers is the checkbox field and The Home Depot and True Value are the checkboxes.
Thanks in advance
<?php $retailers = get_field('retailers'); ?>
<?php if( in_array('The Home Depot', $retailers )): ?>
<img src="<?php echo get_stylesheet_dirctory_url(); ?>/images/thehomedepot.jpg" alt="The Home Depot">
<?php endif; ?>
Make sure that 'The Home Depot' is the value of the checkbox though, not just the label. Output the array with print_r($retailers); so you can see what you're working with.
Here is what I came up with to get everything working if anyone needs the help.
<?php if(in_array('thd', get_field('retailers') ) ) {
echo '<li>';
echo '<a href="';
echo get_field('the_home_depot_product_url');
echo '">';
echo '<img src="../thehomedepot.jpg" alt="The Home Depot" />';
echo '<h3>The Home Depot</h3>';
echo '</a>';
echo '</li>';
} ?>
Related
I would get the image url: mysite/img/test.png but I get this link: mysite/posts/test.png
<?php echo $this->Html->link(
$this->Html->image($post['Post']['image']),
$post['Post']['title']),
array('escape' => false)
);
?>
I have to get another way the url?
Edit:
If you want link to your image, you can do in this way.
<?php echo $this->Html->link(
$this->Html->image($post['Post']['image']),
$this->Html->url('/img/'.$post['Post']['image']),
array('escape' => false)
);
?>
or
<a href="<?php echo $this->Html->url('/img/'.$post['Post']['image']); ?>">
<?php echo $this->Html->image($post['Post']['image']); ?>
</a>
I must stres out that i’m not a developer so i might use some “unsupported” terms :).
Ok the issue, i have created custom post type called Firm. Also i have created field group with 7 fields (text fields mainly, including website URL field and Google map field) and i have made template that displays those fields on frontend page. Once it’s saved all data is saved in database and new post under post type Firm is created. So that all works great. The main problem/question is:
How can i display all new posts in that post type (Firm) on one page? I know i must create some loop, array for those posts, but as i said i’m not developer so i’m kind of stuck with this one.
If someone could give me a hint or some link, or any kind of pointers so i could figure out in what direction to go. Thanks in advance for your answers.
You can refer Wordpress Codex.
Check sample code given below
$args = array( 'post_type' => 'product', 'posts_per_page' => 10 ); // for more parameter check link http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
// Displays Advanced custom field value
the_field('field-name');
echo '<div class="entry-content">';
the_content();
echo '</div>';
endwhile;
Ok thanks so far, thank you #Arun, i have come up with this:
<?php
$args = array( 'post_type' => 'company', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
echo '<div class="entry-content">';
echo '<p>' . '<span>Official Wesite</span>' . '<span> : </span>' . get_field('web_site') . '</p>';
echo '</div>';
endwhile; ?>
<?php
$location = get_field('location');
if( !empty($location) ):
?>
<div class="acf-map">
<div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>"></div>
</div>
<?php endif; ?>
So im strugling now with how to incorporate this google map in loop. I do have title and website link for all posts but i need to have maps for each post as well.
Ok this is what i have at the end, and it's working.
<?php
$args = array( 'post_type' => 'company', 'posts_per_page' => 15 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="boxy">
<div class="acf_company_name">
<h5>Company Name: </h5>
<p><?php the_field('company_name'); ?></p>
</div>
<div class="acf_full_name">
<h5>Full Name: </h5>
<?php the_field('full_name'); ?>
</div>
<div class="acf_vat">
<h5>VAT: </h5>
<?php the_field('vat'); ?>
</div>
<div class="acf_email">
<h5>E-mail: </h5>
<?php the_field('email'); ?>
</div>
<div class="acf_website">
<h5>Official website: </h5>
<?php the_field('website'); ?>
</div>
<?php if ( get_field('logo_company') ) : ?>
<div class="acf_logo_company"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php $image = get_field(logo_company); ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /></a></div>
<?php endif; ?>
<div class="acf_company_location"><?php $location = get_field('company_location');?>
<div class="acf-map">
<div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>" data-lng="<?php echo $location['address']; ?>"></div>
</div></div>
<div class="acf_company_location">
<h5>Company location: </h5>
<?php the_field('company_location'); ?>
</div>
</div>
<?php endwhile; ?>
This is the example in the book, of a simple View Template
// app/View/Common/view.ctp
<h1><?php echo $this->fetch('title'); ?></h1>
<?php echo $this->fetch('content'); ?>
<div class="actions">
<h3>Related actions</h3>
<ul>
<?php echo $this->fetch('sidebar'); ?>
</ul> </div>
And this is how it might be extended
// app/View/Posts/view.ctp
<?php
$this->extend('/Common/view');
$this->assign('title', $post);
My question is:
How can I set a default value/content for (let's say) the title, in order to overwrite if needed ?
Thank you!
Fetch the var. If its not empty, echo it, otherwise echo the default.
$title = $this->fetch('title');
echo !empty($title) ? $title : 'Default';
I am new at cakephp 1.3. I am trying to create an Edit User Form with Form Helper in Cakephp 1.3.
I am unable to customize the alignments of the form elements, for example:
echo $this->Form->create('Model', array('action' => 'edit_users','id' => 'UserForm'));
echo $this->Form->input('First Name',array('style'=>'width:100px','label'=>'First Name:'));
echo $this->Form->input('Last Name',array('style'=>'width:100px','label'=>'Last Name:'));
echo $this->Form->input('Position',array('style'=>'width:100px','label'=>'Position:'));
I want the first two input fields on a single line and the third input field on the second line. I have tried it with div false, but its not working. How can I achieve this?
div=>false works but you will need to add some css
echo $this->Form->create('Model', array('action' => 'edit_users','id' => 'UserForm'));
echo '<div id="first">';
echo '<div class="leftalign">';
echo $this->Form->input('First Name',array('div'=>false,'label'=>'First Name:'));
echo '</div>';
echo '<div class="rightalign">';
echo $this->Form->input('Last Name',array('div'=>false,'label'=>'Last Name:'));
echo '</div>';
echo $this->Form->input('Position',array('style'=>'width:100px','label'=>'Position:'));
CSS
#first .leftalign{
float: left;
width:300px;
}
#first .rightalign{
clear:none;
float: right;
width:300px;
}
#first label,#first input{
width: 100px;
}
You can edit the css as per your requirements
this one worked for me
<table border='0'>
<tr><td>
<?php echo $this->Form->create('Model', array('action' => 'edit_users','id' => 'UserForm'));
echo $this->Form->input('First Name',array('label'=>'First Name:'));?>
</td><td>
<?php echo $this->Form->input('Last Name',array('label'=>'Last Name:'));?></td>
</tr>
<tr><td>
<?php echo $this->Form->input('Position',array('label'=>'Position:'));?>
</td>
</table>
Just put your form controls in a table and you can align them on the form any how you want!
I'm trying to have an auto complete box in my application,where the values are retrieved from a table.
I want to share a form with set of users in the Users table. i have a link called 'Share' and when I click the link, the autocomplete box is generated.
Now when I type in the text box any letter, I want it to be auto suggested.
This is my view file, /views/main/home.ctp
<?php echo $javascript->link('prototype');?>
<?php echo $javascript->link('scriptaculous');?>
<?php echo $javascript->link('effects');?>
<?php echo $javascript->link('controls');?>
$(document).ready(function(){
$(".Share<?=$r['Form']['id'];?>").click(function(){
$("#share<?=$r['Form']['id'];?>").toggle("show");
});
});
<li id="Share<?php echo $r['Form']['id']?>">
Share
<div id="share<?php echo $r['Form']['id']?>">
<?php echo $form->create('User', array('url' => '/forms/share'));?>
<?php echo $ajax->autoComplete('User.name', '/forms/autoComplete');?>
<?php echo $form->end('Share');?>
</div>
</li>
This is my auto_complete.ctp file:/views/forms/auto_complete.ctp
<?php echo $javascript->link('scriptaculous.js');?>
<?php echo $javascript->link('prototype.js');?>
<ul>
<?php foreach($users as $user): ?>
<li><?php echo $user['User']['name']; ?></li>
<?php endforeach; ?>
</ul>
And this this the function in the forms_controller: /forms/autoComplete
function autoComplete()
{
$this->set('users',$this->User->find('all',array('conditions'=>array('User.name LIKE' => $this->data['User']['name'].'%'))));
$this->layout = "ajax";
}
I get the results in the auto_complete.ctp file, i.e, if I type in the letter 's' in the autoComplete text box, I get the corresponding users in that file, but I do not get those values in the text box. Someone help me please.
Well I found the answer myself.
Autocomplete feature of cakephp does not work if you use JQuery.
I removed the line
<?php echo $javascript->link('jquery');?>
and it is working...
EDIT:
If you also want to work with jquery and need the jquery.js file, you would need to enable no-conflict mode in jQuery,as given in the site
http://docs.jquery.com/Using_jQuery_with_Other_Libraries