count up the rows in acf (repeater-field) and add html output for every row - advanced-custom-fields

I want to output a list element () for each row of an ACF repeater field. As soon as a new row is created, a new list element shoul be created with the value of the counter (cout up).
here is the code. the list elements should cout up according to the number of rows:
HTML:
<ul>
<li data-id="1" class="active">1</li>
<li data-id="2">2</li>
<li data-id="3">3</li>
<li data-id="4">4</li>
<li data-id="5">5</li>
<li data-id="6">6</li>
<li data-id="7">7</li>
<li data-id="...">...</li>
</ul>
PHP (ACF):
<?php
$i = 1;
if (have_rows('referenz-slide')) :
$counter = 0;
while (have_rows('referenz-slide')) : the_row();
$counter++;
// vars
$title = get_sub_field('title');
$link = get_sub_field('link');
$text = get_sub_field('text');
?>
<?php $state = "";
if ($i == 1) {
$state = "active";
} else {
$state = "hidden";
} ?>
<div class="referenz-content <?php echo $state; ?>" id="ref-<?php echo $i; ?>" data-referenz="<?php echo $i; ?>">
<h4 class="referenz-headline"><?php echo $title; ?></h4>
<p><?php echo $text; ?></p>
Jetzt mehr erfahren
</div>
<?php $i++;
endwhile; ?>
<?php else : ?>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
I would like to increment the list items and the value of the data id (html output) according to the number of ACF rows. Can someone help?

So you pretty much have it all there already
<ul>
<?php while (have_rows('referenz-slide')) : the_row();?>
<li data-id="<?php echo $i;?>" class="<?php echo $state; ?>">
<?php echo $i;?>
</li>
<?php $i++; ?>
<?php endwhile; ?>
</ul>

Related

How can I save the items of answers for a questions in an array so that I send them to the database using a controller and a model

The code below is the view page used to display the different kinds of questions and their choices.. Questions like Fill in the blanks and multiple answer consists of more than one answer element.
<?php echo form_open('courseware/saveanswer'); ?>
<?php if(count($test_questions)):?>
<?php $i = 1 ?>
<ol>
<?php foreach($test_questions as $test_question):?>
<li>
<?php if($test_question->question_type == 'Fill-blanks'):?>
<?php $test_question->question_text = str_replace('___',form_input(array('name'=>'answer[]','id'=>'answer_'.$i++,'type'=>'text','size'=>'8')),$test_question->question_text)?>
<?php endif ?>
<?php echo $test_question->question_text ?>
<?php if($test_question->question_type == 'Multi-choice'):?>
<?php $choices = explode("\n", $test_question->question_choices)?>
<?php if(count($choices)):?>
<ul>
<?php foreach($choices as $choice):?>
<li><?php echo form_radio('answer'.$test_question->question_id,$choice) ?> <?php echo $choice ?></li>
<?php endforeach ?>
</ul>
<?php echo form_submit('$save', 'Save') ?>
<?php endif ?>
<?php elseif($test_question->question_type == 'Multi-answer'):?>
<?php $choices = explode("\n", $test_question->question_choices)?>
<?php if(count($choices)):?>
<ul>
<?php foreach($choices as $choice):?>
<li><?php echo form_checkbox('answer',$choice) ?> <?php echo $choice ?></li>
<?php endforeach ?>
</ul>
<?php echo form_submit('$save', 'Save') ?>
<?php endif ?>
<?php elseif($test_question->question_type == 'True/False'):?>
<ul>
<li><?php echo form_radio('answer_'.$test_question->question_id,1) ?> True</li>
<li><?php echo form_radio('answer_'.$test_question->question_id,0) ?> False</li>
</ul>
<?php echo form_submit('$save', 'Save') ?>
<?php else:?>
<?php endif ?>
</li>
<?php endforeach?>
<?php echo form_close(); ?>
below is a screenshot.
The question page looks like this ..
I want an array that has all the answers selected and sends the data to the database
The database consists of the table tbl_response and has the columns
test_reponse_id,
test_reponse_text ,
question_id ,
there's a number of ways to store multiple elements in a single value. You can use an implode() function to save as a string with a separator, as you are already doing with the $test_question->question_choices , which is separated by a '\n'. The cleanest alternative to that is often using json_encode().
either way, as you're presumably going to be comparing the selected answer(s) to something else, i suggest being careful about keeping the format and order consistent.

Magento is not updating Shipping cost on changing the Shipping method radio button

I change the shipping method as you can see in the screenshot but magento does not refresh the inner page with the calculated total shipping cost.I think this is a bug in version 1.9. Here you can see the screenshot .Magento ver. 1.9.2.4
When I change the radio button from one shipping method the onestepcheckout does not refresh the inner page with calculated cost.
How can I refresh the inner page with javascript.
Thanks
Add the below code in available.phtml file
<?php if (!($_shippingRateGroups)): ?>
<strong><?php echo Mage::helper('oscheckout')->__('Sorry, no quotes are available for this order at this time.') ?></strong>
<?php else: ?>
<dl class="shipment-methods">
<?php $methodcount = count($_shippingRateGroups); $check_default = 1; 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 <?php echo $check_default == 1 ? 'checked="checked"':'' ?> name="shipping_method" type="radio" class="validate-one-required-by-name" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>" />
<label for="s_method_<?php echo $_rate->getCode() ?>"> <?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 Mage::helper('oscheckout')->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
<?php endif; ?>
</strong>
</label>
<?php endif ?>
</dt>
<?php endforeach; $check_default++; ?>
<?php endforeach; ?>
</dl>
<?php endif;
?>
Add this script in the same file
<script type="text/javascript">
<?php if($methodcount >= 1): ?>
document.observe('dom:loaded', function(){
shipping.loadReview();
var payment_methods = $('ajax-payment-methods');
//payment_methods.update('<div class="ajax-load"> </div>');
payment.reloadPaymentBlock();
// reloadPaymethod();
});
<?php endif; ?>
$$('dl.shipment-methods input').invoke('observe', 'click', function() {
shipping.loadReview();
var payment_methods = $('ajax-payment-methods');
//payment_methods.update('<div class="ajax-load"> </div>');
payment.reloadPaymentBlock();
// reloadPaymethod();
});
</script>

How to show the message “No Products” when there's no products in my custom block?

I need to show the message "No Products" or "There are no products matching the selection" when there's nothing to show in my block.
<?php
$manufacturer = Mage::registry('current_product')->getMerchantName();
$productCollection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('merchant_name',$manufacturer);
$productCollection->getSelect()->order('RAND()');
$productCollection->getSelect()->limit(5);
foreach ($productCollection as $_product)
?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(228) ?>" width="228" height="228" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
<div class="product-details">
<p class="product-name"><?php echo $this->htmlEscape($_product->getName()) ?></p>
<?php
$merchant_name = $_product->getAttributeText('merchant_name');
if ($merchant_name){?>
<div>by <?php echo $merchant_name;?> </div>
<?php }
else if ($_product->getIsEbayaffiliate()) { ?>
<div>by eBay</div>
<?php }
else { ?>
<div>by Home Done</div>
<?php } ?>
Also I need to add getPriceHtml to the above code to show the product price.
I have tried <?php echo $this->getPriceHtml($_item, true) ?>
There you go:
(Advice: use closed tags like <?php if(): ?> for better readability)
<?php if(is_array($productCollection) && count($productCollection) ): ?>
<?php foreach ($productCollection as $_product): ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(228) ?>" width="228" height="228" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
<div class="product-details">
<p class="product-name"><?php echo $this->htmlEscape($_product->getName()) ?></p>
<?php $merchant_name = $_product->getAttributeText('merchant_name'); ?>
<?php if ($merchant_name):?>
<div>by <?php echo $merchant_name;?> </div>
<?php elseif($_product->getIsEbayaffiliate()): ?>
<div>by eBay</div>
<?php else: ?>
<div>by Home Done</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
<?php else: ?>
// here goes whatever you want to display if no products found in list
<?php endif; ?>

How do I echo the each posts category in wordpress

I am looking to make wordpress print/echo the category name of a post into it's class. I need this to work on the index page inside the main loop. Here is what I mean:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article class="<?php ** I NEED THIS CODE ** ?>">
<div>
<h2><?php the_title(); ?></h2>
</div>
<?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } else {} ?>
</article>
<?php endwhile; ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
Hopefully you understand my poor description of my issue. Thanks
From http://lorelle.wordpress.com/2007/09/06/using-wordpress-categories-to-style-posts/
Add the following to your theme's functions.php file:
function the_category_unlinked($separator = ' ') {
$categories = (array) get_the_category();
$thelist = '';
foreach($categories as $category) { // concate
$thelist .= $separator . $category->category_nicename;
}
echo $thelist;
}
And the corresponding markup would be:
<article class="<?php the_category_unlinked(' '); ?>">

how i can do featured post slider set category based?

my featured post slider set as a tags. i want it set category base. how i can do it?my site http://techgajot.com
my featured post slider html code?
<script type="text/javascript">
//<![CDATA[
jQuery(window).load(function() {
jQuery('#featured').flexslider({
slideshowSpeed: 6000,
directionNav:false,
pauseOnHover:true,
manualControls: '.flexslide-custom-controls li a',
controlsContainer: '.container'
});
});
//]]>
</script>
<div class="featured">
<div class="container">
<div id="featured" class="flexslider">
<ul class="slides">
<?php
$count = 1;
$featurecount = get_option('solostream_features_number');
$my_query = new WP_Query("tag=featured&showposts=$featurecount");
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate[] = $post->ID; ?>
<li id="narrow-feature-post-<?php echo $count; ?>"<?php echo solostream_featureclass(); ?>>
<div class="slide-container clearfix">
<?php if ( get_post_meta( $post->ID, 'video_embed', true ) ) { ?>
<div class="feature-video">
<div class="video"><?php echo get_post_meta( $post->ID, 'video_embed', true ); ?></div>
</div>
<?php } else { ?>
<div class="feature-image">
<?php solostream_feature_image(); ?>
</div>
<?php } ?>
<div class="flex-caption">
<div class="excerpt">
<h2 class="post-title"><?php the_title(); ?></h2>
<?php if ( 'post' == get_post_type() ) { ?>
<?php include (TEMPLATEPATH . "/postinfo.php"); ?>
<?php } ?>
<?php the_excerpt(); ?>
<p class="readmore"><a class="more-link" href="<?php the_permalink() ?>" rel="nofollow" title="<?php _e("Permanent Link to", "solostream"); ?> <?php the_title(); ?>"><?php _e("সম্পূর্ন অংশ", "solostream"); ?></a></p>
</div>
</div>
</div>
</li>
<?php $count = $count + 1 ?>
<?php endwhile; ?>
</ul>
</div>
<div class="controls-container clearfix">
<ul class="flexslide-custom-controls clearfix">
<?php
$count = 1;
$featurecount = get_option('solostream_features_number');
$my_query = new WP_Query("tag=featured&showposts=$featurecount");
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate[] = $post->ID; ?>
<li><?php echo $count; ?></li>
<?php $count = $count + 1 ?>
<?php endwhile; ?>
</ul>
</div>
</div>
</div>
how i can do it. my featured post slider tags now= featured. when i put "featured" any post tags option then it show featured post. now i want it like category base. i select here any category.then that category all post show featured post.
If I understood you right ( difficult ike #dda noted ) Changing this line :
$my_query = new WP_Query("tag=featured&showposts=$featurecount");
to
$my_query = new WP_Query("category_name=featured&showposts=$featurecount");
Will make the same query from tag to category using name ..
If you use ID , then
$query = new WP_Query( 'cat=2,7,23,35' );
Or all posts that share this category :
$query = new WP_Query( 'category_name=staff' );
Read more HERE ON THE CODEX