I am not sure how to keep my checkbox checked after I hit the Apply button. I am thinking I have to add is_set to the output but I am not sure how or where to add it in. Here is my code below any help would be great.
<div id="product-filter-options">
<form method="GET">
<?php
$scooters = $_GET['scooters'];
$product_type = $_GET['product_type'];
$bike_sub_category = $_GET['bike_sub_category'];
$model_year = $_GET['model_year'];
?>
<?php
function get_terms_chekboxes($taxonomies, $args) {
$terms = get_terms($taxonomies, $args);
foreach($terms as $term) {
$output .= '<span><label for="'.$term->slug.'"><input type="checkbox" id="'.$term->slug.'" name="'.$taxonomies.'" value="'.$term->slug.'" >' .$term->name.'</label></span>';
}
return $output;
}
echo '<div class="check-contain">';
echo '<h4>Bicycle Brand</h4>';
echo get_terms_chekboxes('scooters', $args = array('hide_empty'=>true));
echo '<span class="slide-show-more">See More</span>';
echo '</div>';
echo '<div class="check-contain">';
echo '<h4>Bicycle Type</h4>';
echo get_terms_chekboxes('product_type', $args = array('hide_empty'=>true));
echo '<span class="slide-show-more">See More</span>';
echo '</div>';
echo '<div class="check-contain">';
echo '<h4>Bicycle Sub-Type</h4>';
echo get_terms_chekboxes('bike_sub_category', $args = array('hide_empty'=>true));
echo '<span class="slide-show-more">See More</span>';
echo '</div>';
echo '<div class="check-contain">';
echo '<h4>Model Year</h4>';
echo get_terms_chekboxes('model_year', $args = array('hide_empty'=>true));
echo '<span class="slide-show-more">See More</span>';
echo '</div>';
?>
<button type="submit">Apply</button>
Thanks in advance.
i would like to change a link to target="_blank" (opening in a new window, or tab) but can#t fix it. i´m a fool in php and my try&error-method did´t work. can anybody help me?
Thank you so much!
original code from the parallax one theme (wordpress)
<?php
if(!empty($parallax_one_contact_info_item_decoded)){
foreach($parallax_one_contact_info_item_decoded as $parallax_one_contact_item){
if(!empty($parallax_one_contact_item->link)){
echo '<div class="col-sm-4 contact-link-box col-xs-12">';
if(!empty($parallax_one_contact_item->icon_value)){
echo '<div class="icon-container"><span class="'.esc_attr($parallax_one_contact_item->icon_value).' colored-text"></span></div>';
}
if(!empty($parallax_one_contact_item->text)){
echo ''.$parallax_one_contact_item->text.' ';
}
echo '</div>';
} else {
echo '<div class="col-sm-4 contact-link-box col-xs-12">';
if(!empty($parallax_one_contact_item->icon_value)){
echo '<div class="icon-container"><span class="'.esc_attr($parallax_one_contact_item->icon_value).' colored-text"></span></div>';
}
if(!empty($parallax_one_contact_item->text)){
if(function_exists('icl_translate')){
echo ''.icl_translate('Contact',$parallax_one_contact_item->id.'_contact',esc_attr($parallax_one_contact_item->text)).'';
} else {
echo ''.esc_attr($parallax_one_contact_item->text).'';
}
}
echo '</div>';
}
}
}
?>
Simply add target="_blank" in your anchor tag. For example :
echo '<a target="_blank" href="'.$parallax_one_contact_item->link.'" class="strong">'.$parallax_one_contact_item->text.' </a>';
Try this:
<?php
if(!empty($parallax_one_contact_info_item_decoded)){
foreach($parallax_one_contact_info_item_decoded as $parallax_one_contact_item){
if(!empty($parallax_one_contact_item->link)){
echo '<div class="col-sm-4 contact-link-box col-xs-12">';
if(!empty($parallax_one_contact_item->icon_value)){
echo '<div class="icon-container"><span class="'.esc_attr($parallax_one_contact_item->icon_value).' colored-text"></span></div>';
}
if(!empty($parallax_one_contact_item->text)){
echo '<a target="_blank" href="'.$parallax_one_contact_item->link.'" class="strong">'.$parallax_one_contact_item->text.' </a>';
}
echo '</div>';
} else {
echo '<div class="col-sm-4 contact-link-box col-xs-12">';
if(!empty($parallax_one_contact_item->icon_value)){
echo '<div class="icon-container"><span class="'.esc_attr($parallax_one_contact_item->icon_value).' colored-text"></span></div>';
}
if(!empty($parallax_one_contact_item->text)){
if(function_exists('icl_translate')){
echo '<a target="_blank" href="" class="strong">'.icl_translate('Contact',$parallax_one_contact_item->id.'_contact',esc_attr($parallax_one_contact_item->text)).'</a>';
} else {
echo '<a target="_blank" href="" class="strong">'.esc_attr($parallax_one_contact_item->text).'</a>';
}
}
echo '</div>';
}
}
}
?>
Note: Added target="_blank" in each hyperlink.
Hi I would like to order custom fields in wordpress. I've got it displaying the single project. But can't figure out how I can get it to display in order. I've created a field called project_order which works correctly on another page.
But i'm not used to this sort of php with order by. This is a project designed by someone else so i'm trying to pick up and learn how it was built.
<?php
//associate sector to product projects page
$sector['construction'] = 131;
$sector['timber-frame'] = 235;
$sector['industrial'] = 253;
$sector['agriculture'] = 263;
//link to view all projects for product
echo '<p>View all projects</p>';
?>
</div>
<div class="span5">
<div id="latestproject">
<h2>Latest Project</h2>
<?php
//get latest projects
$rows = get_field('projects', $sector [$post->post_name] , '&order=ASC');
//display latest project
if ($rows) {
echo '<div class="row">';
if ($rows[0]['project_pageturner']) {
echo '<a href="'.$rows[0]['project_pageturner'].'" target="_blank">';
} else if ($rows[0]['project_pdf']) {
echo '<a href="'.wp_get_attachment_url($rows[0]['project_pdf']).'" target="_blank">';
} else {
echo "<a href=\"javascript:alert('No PDF uploaded for this item.')\">";
}
echo '<div class="span2">';
if ($rows[0]['project_thumbnail']) {
echo wp_get_attachment_image($rows[0]['project_thumbnail'], 'full');
} else {
echo '<img src="'.get_bloginfo('template_directory').'/images/defaultproject.jpg" alt="">';
}
echo '</div>';
echo '<div class="span3">';
echo '<p><strong>'.$rows[0]['project_title'].'</strong></p>';
echo '<p>View project »</p>';
echo '</div>';
echo '</a>';
echo '</div><!--row-->';
} else {
echo '<p>No projects to display currently.</p>';
}
?>
I'm guessing it will have something to do with.
$rows = get_field('projects', $sector [$post->post_name]);
Try below code, may be this resolve your problem.
<?php
wp_reset_query();
//associate sector to product projects page
$sector['construction'] = 131;
$sector['timber-frame'] = 235;
$sector['industrial'] = 253;
$sector['agriculture'] = 263;
//link to view all projects for product
echo '<p>View all projects</p>';
?>
</div>
<div class="span5">
<div id="latestproject">
<h2>Latest Project</h2>
<?php
//get latest projects
$rows = get_field('projects', $sector [$post->post_name] , '&order=ASC');
//display latest project
if ($rows) {
echo '<div class="row">';
if ($rows[0]['project_pageturner']) {
echo '<a href="'.$rows[0]['project_pageturner'].'" target="_blank">';
} else if ($rows[0]['project_pdf']) {
echo '<a href="'.wp_get_attachment_url($rows[0]['project_pdf']).'" target="_blank">';
} else {
echo "<a href=\"javascript:alert('No PDF uploaded for this item.')\">";
}
echo '<div class="span2">';
if ($rows[0]['project_thumbnail']) {
echo wp_get_attachment_image($rows[0]['project_thumbnail'], 'full');
} else {
echo '<img src="'.get_bloginfo('template_directory').'/images/defaultproject.jpg" alt="">';
}
echo '</div>';
echo '<div class="span3">';
echo '<p><strong>'.$rows[0]['project_title'].'</strong></p>';
echo '<p>View project »</p>';
echo '</div>';
echo '</a>';
echo '</div><!--row-->';
} else {
echo '<p>No projects to display currently.</p>';
}
wp_reset_query();
?>
Thanks.
This is an extension to another post by myself (How To Detect a Button Click in the Expanded Accordion Row).
After adding some additional rows in the details section of my accordion control and moving the 'Select' button into a separate div, I am only getting the values from the first accordion row. This was my original issue. Just to confirm the original solution worked, if I move my 'Select' button into the save div containing the label for Location, it passes the correct location label ('labelAccordionLocation') value for what ever row I have expanded but always passes the first row's name label value. It also works correct if the 'Select' button is in the save div as the Name label ('labelAccordionName').
Based on the suggestion in my other post (which worked flawlessly for my original example), it seems that I now need to figure out how to identify the div that contains each label so I can then pass it's value when the 'Submit' button is clicked. Although, this is still just an amateur's way of thinking.
<div class="accordion" id="accordion2">
<?php
// SQL stuff here...
$group = null;
while ($row = odbc_fetch_array($db)) {
if ($row['Name'] != $group) {
echo "<div class='accordion-heading'>";
echo "<a class='accordion-toggle' data-toggle='collapse'
data-parent='#accordion2' href='#", $row['Number'],"'>
<button id='buttonAccordionToggle'
data-target='#", $row['Number'],"'>", $row['Name'],"</button></a>";
echo "</div>";
echo "<div id='", $row['Number'],"' class='accordion-body collapse'>";
echo "<div class='accordion-inner'>";
echo "<div class='control-group' style='min-height: 50px'>";
echo "<div class='row-fluid show-grid'>";
echo "<div class='span12'>";
echo "<div class='span1'>";
echo "<label>Name:</label>";
echo "</div>";
echo "<div class='span11'>";
echo "<label id='labelAccordionName'>",
$row['Name'],"</label>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "<div class='row-fluid show-grid'>";
echo "<div class='span12'>";
echo "<div class='span1'>";
echo "<label>Location:</label>";
echo "</div>";
echo "<div class='span11'>";
echo "<label id='labelAccordionLocation'>",
$row['Location'],"</label>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "<div class='row-fluid show-grid'>";
echo "<div class='span12'>";
echo "<a id='select' class='btn'>Select</a>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
$group = $row['Name'];
}
}
}
?>
</div>
<div id="divDetails" style="display: none;">
<label>Name:</label>
<label id="labelName"></label><br />
<label>Location:</label>
<label id="labelLocation"></label><br />
<a id="close" class="btn">Close</a>
</div>
<script>
// Hide the accordion and show the hidden div
$('a.btn').click(function() {
$('#accordion2').hide();
$('#divDetails').show();
// Pass the label value from the accordion row to the hidden div label
$('#labelName').html($('.accordion-body.in .labelAccordionName').html());
$('#labelLocation').html($('.accordion-body.in .labelAccordionLocation').html());
});
// Hide the div and show the accordion again
$('#close').click(function() {
$('#accordion2').show();
$('#divDetails').hide();
});
// Only allows one row to be shown at a time
$('.accordion-toggle').click(function() {
var $acc = $('#accordion2');
$acc.on('show', '.collapse', function() {
$acc.find('.collapse.in').collapse('hide');
});
});
$(document).ready(function(){
// On dropdown change, pass in value to populate accordion/details
$('#dd').change(function() {
var r = $(this).val();
location.href = "test.php?src=" + r;
});
});
</script>
I did some searching on the jQuery site to try and figure this one out but unfortunately was unable to get it working. I'll do my best to give any additional information that is needed.
Edits
I changed the label's to use classes instead of id's. Although a great suggestion, I did not have to apply a new class 'activeAccordion'. Since the class 'in' is applied to the expanded row, I was able to use it for access as seen below. I also updated the jsFiddle and provided a link at the bottom.
$('a.btn').click(function() {
$('#accordion2').hide();
$('#divDetails').show();
$('#labelName').html($('.accordion-body.in .labelAccordionName').html());
$('#labelLocation').html($('.accordion-body.in .labelAccordionLocation').html());
});
Working jsFiddle
http://jsfiddle.net/N8JuQ/
You should consider escaping out of PHP in your if statement and only jump back in to echo the variables. Also read up on alternative syntax: http://php.net/manual/en/control-structures.alternative-syntax.php
while ($row = odbc_fetch_array($db)) {
if ($row['Name'] != $group){
?>
<div class='accordion-heading'>
<a class='accordion-toggle' data-toggle='collapse' data-parent='#accordion2' href='#", <?php echo $row['Number']; ?>,"'>
<button id='buttonAccordionToggle' data-target='#", <?php echo $row['Number']; ?>,"'>", <?php echo $row['Name']; ?>,"</button></a>
</div>
<div id='", <?php echo $row['Number']; ?>,"' class='accordion-body collapse'>
<div class='accordion-inner'>
...
...
...
<?php
}
?>
when generating html with php, as long as you are iterating be careful with IDs. Never generate same ID in a DOM, it messes things really bad. (ie. select, labelAccordionName, buttonAccordionToggle) I suggest using classes or generating unique IDs plus a generic class
you should have something like :
<div class="accordion" id="accordion2">
<?php
// SQL stuff here...
$group = null;
while ($row = odbc_fetch_array($db)) {
if ($row['Name'] != $group) {
echo "<div class='accordion-heading'>";
echo "<a class='accordion-toggle' data-toggle='collapse'
data-parent='#accordion2' href='#", $row['Number'],"'>
<button class='buttonAccordionToggle'
data-target='#", $row['Number'],"'>", $row['Name'],"</button></a>";
echo "</div>";
echo "<div id='", $row['Number'],"' class='accordion-body collapse'>";
echo "<div class='accordion-inner'>";
echo "<div class='control-group' style='min-height: 50px'>";
echo "<div class='row-fluid show-grid'>";
echo "<div class='span12'>";
echo "<div class='span1'>";
echo "<label>Name:</label>";
echo "</div>";
echo "<div class='span11'>";
echo "<label class='labelAccordionName'>",
$row['Name'],"</label>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "<div class='row-fluid show-grid'>";
echo "<div class='span12'>";
echo "<div class='span1'>";
echo "<label>Location:</label>";
echo "</div>";
echo "<div class='span11'>";
echo "<label class='labelAccordionLocation'>",
$row['Location'],"</label>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "<div class='row-fluid show-grid'>";
echo "<div class='span12'>";
echo "<a class='select btn'>Select</a>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
$group = $row['Name'];
}
}
}
?>
</div>
<div id="divDetails" style="display: none;">
<label>Name:</label>
<label id="labelName"></label><br />
<label>Location:</label>
<label id="labelLocation"></label><br />
<a id="close" class="btn">Close</a>
</div>
<script>
something like that, didn't check as you don't provided a jsfiddle. As for your data to retrieve correctly, I would suggest adding a class on active accordion-body then in your finds use this class to select the correct element :
$('.accordion-toggle').click(function() {
var $acc = $('#accordion2');
$('.activeAccordion').removeClass('activeAccordion');
$(''+$(this).next('.buttonAccordionToggle').data('target')).addClass('activeAccordion');
$acc.on('show', '.collapse', function() {
$acc.find('.collapse.in').collapse('hide');
});
});
then use this new class :
$('#labelName').html($('accordion-body.activeAccordion .labelAccordionName').html()));
$('#labelLocation').html($('accordion-body.activeAccordion .labelAccordionLocation').html()));
I´m trying to display a list of div with images using the repeater field of ACF.
this is the code i´m using:
<?php $query = new WP_Query( 'post_type=artworks_post&posts_per_page=-1&order=DESC' ); ?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<?php
$slides = get_field('project_thumbnails'); // Grabs the array
// Check if there is any data in the array before looping
if($slides) {
echo '<div id="project_slider" class="item">';
foreach($slides as $s) {
echo '<a href="#">';
echo '<img src="'.$s['project_thumb'].'" alt="" />';
echo '</a>';
}
echo '<div class="art_title">';
echo '<p>SWEET LIFE2</p>';
echo '</div>';
echo '<div class="mask">';
echo '</div>';
}
?>
<?php endwhile; // end of the loop. ?>
The problem with this is that it displays all images in the same div, instead of display every image of the repeater field in a new div.
what i´m doing wrong?
Im not a php expert but,i think is just a matter of missing closing tags for the first div, also im gonna put another div within the loop, it looks like this:
<?php $slides = get_field('project_thumbnails');
// Grabs the array
// Check if there is any data in the array before looping
if($slides) {
//we need to close this div
echo '<div id="project_slider" class="item">';
foreach($slides as $s) {
echo '<div class="aimagediv" >'; //adding the start tag of the div
echo '<a href="#">';
echo '<img src="'.$s['project_thumb'].'" alt="" />';
echo '</a>';
echo '</div>'; //CLOSING THE DIV JUST ADDED
}
echo '<div class="art_title">';
echo '<p>SWEET LIFE2</p>';
echo '</div>';
echo '<div class="mask">';
echo '</div>';
echo '</div>'; //closing the first div,not sure if you want this, its optional
}
?> <?php endwhile; // end of the loop. ?>
Another alternative would be this (just figuring out what's the resulting layout you're expecting):
<?php $slides = get_field('project_thumbnails');
// Grabs the array
// Check if there is any data in the array before looping
if($slides) {
//we need to close this div
foreach($slides as $s) {
echo '<div id="project_slider" class="item">';
echo '<a href="#">';
echo '<img src="'.$s['project_thumb'].'" alt="" />';
echo '</a>';
echo '</div>'; //CLOSING THE DIV JUST ADDED
}
echo '<div class="art_title">';
echo '<p>SWEET LIFE2</p>';
echo '</div>';
echo '<div class="mask">';
echo '</div>';
}
?> <?php endwhile; // end of the loop. ?>
Hopefully this would be enough.