current post custom taxonomy link in WordPress - taxonomy

I am trying to get current post custom taxonomy link and name separately to put some schema data and my code is:
<?php $args = array('taxonomy' => 'developer'); ?>
<?php $tax_menu_items = get_categories( $args );
foreach ( $tax_menu_items as $tax_menu_item ):?>
<meta itemprop="url" content="<?php echo get_term_link($tax_menu_item,$tax_menu_item->taxonomy); ?>"></meta>
<a href="<?php echo get_term_link($tax_menu_item,$tax_menu_item->taxonomy); ?>">
<span itemprop="name"><?php echo $tax_menu_item->name; ?></span></a>
<?php endforeach; ?>
</div>`
The problem is that the above code is displaying all the "developer" which have at least one post and not the current post taxonomy.
How can I fix this!

<meta itemprop="url" content="<?php $terms = wp_get_post_terms( $post->ID, 'developer'); foreach($terms as $term) {
echo "" . get_term_link($term) . ""; } ?>"></meta>
<?php $terms = wp_get_post_terms( $post->ID, 'developer'); foreach($terms as $term) {
echo '<span itemprop="name">' . $term->name . '</span>'; }
?>

Related

Relationship Field meta_query Not Working Why?

<?php
/*
* Query posts for a relationship value.
* This method uses the meta_query LIKE to match the string "123" to the database value a:1:{i:0;s:3:"123";} (serialized array)
*/
$doctors = get_posts(array(
'post_type' => 'star',
'meta_query' => array(
array(
'key' => 'location', // name of custom field
'value' => '"' . get_the_ID() . '"', // can you please explain this? my relationship field is currently Post Object not sure how
'compare' => 'LIKE'
)
)
));
?>
<?php if( $doctors ): ?>
<ul>
<?php foreach( $doctors as $doctor ): ?>
<?php
$photo = get_field('photo', $doctor->ID);
?>
<li>
<a href="<?php echo get_permalink( $doctor->ID ); ?>">
<img src="<?php echo $photo['url']; ?>" alt="<?php echo $photo['alt']; ?>" width="30" />
<?php echo get_the_title( $doctor->ID ); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
base on the documentation of acf this is the right code but testing it not working why?..........................................thank you guys for helping me..

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

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>

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 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(' '); ?>">