I have a link that passes variable to another page but I want to display that link only on some condition so how to place it inside php code.
Product
<?php
echo 'Product';
?>
This doesn't work.
Simply, put your anchor link in if condition:
<?php
if (YOUR_CONDITION_HERE) {
echo 'Product';
}
?>
OR
<?php
if (YOUR_CONDITION_HERE) {
?>
Product
<?php
}
?>
Above condition will display your link only when your condition is TRUE.
Otherwise, it will hide.
Your second line is incorrect why are you opening your php tags again while you're in a echo ?
Please try the following :
<?php
echo 'Product';
?>
Your echo field should be.
Product
<?php
echo 'Product';
?>
You dont have to print echo inside3 echo so u hv to do this way!
<?php
echo 'Product';
?>
Related
I have 2 variables in phtml and want to make them a link.
<?php
$_reviewCount = $_ratingSummary->getReviewsCount();
$_reviewUrl=$_product->getRequestPath().'#reviews';
<!--Here if review count is 1 i want to show as "Review" else "Reviews" -->
<?php echo $_reviewCount ?>
<?php echo "<a href='".$_reviewUrl."'>Review</a>" ?>
<?php ($_reviewCount == 1 ) ? __('Review') : __('Reviews') ?>
But the above shows only keyword 'review' in lowercase .
Just rewrite your code to first define the singular or plural form and then echo it:
<?php
if($reviewCount==1){$text='Review';}else{$text='Reviews';}
echo "$_reviewCount $text";
?>
BTW i'd change the if condition to >1 because your code echoes Reviews if the count of reviews is 0.
<?php
if($_reviewCount>1){$text='Reviews';}else{$text='Review';}
echo "$_reviewCount $text";
?>
I'm displaying a gallery on my wordpress site using the following code:
<?php echo do_shortcode('[satellite gallery=2 auto=off caption=off thumbs=on]'); ?>
Now I've added a custom post value/field called 'guitLink' where I can add the gallery number which I want to then use in the above shortcode, so something like this:
<?php echo do_shortcode('[satellite gallery=' .get_post_custom_values('guitLink'). 'auto=off caption=off thumbs=on]'); ?>
Any ideas how to achieve this?
Use:
<?php $guitLink = get_post_custom_values('guitLink');
echo do_shortcode('[satellite gallery=' .$guitLink[0]. ' auto=off caption=off thumbs=on]'); ?>
Instead of
<?php echo do_shortcode('[satellite gallery=' .get_post_custom_values('guitLink'). ' auto=off caption=off thumbs=on]'); ?>
Currently in the PHP file it has:
<?php if($myfooter_text){?>
<?php echo of_get_option('footer_text'); ?>
<?php } else { ?>
something else here
<?php } ?>
What I would like is for it to insert the footer text it finds using $myfooter_text but also add a link to the end of whatever has been pre filled in the footer text. I tried to use concatenation with the following:
<?php echo of_get_option('footer_text') . 'mylink; ?>
However this still just shows the predefined footer text and not the additional content. Is there a way to do this? I'm aware it could be added in the footer area of the dashboard but this isnt what i want to do.
Try it like this:
<?php echo of_get_option('footer_text'); ?> mylink
You can concatenate them as well like this or do it your way and be sure you close all the quotes:
<?php echo of_get_option('footer_text') . 'mylink'; ?>
this is the piece of code I'm not sure how to deal with:
<?php echo get_post_meta($post->ID, 'smartslider2', true); ?>
<?php echo do_shortcode('[smartslider2 slider="InsertHere"]'); ?>
I simply want to insert the first echo instead of InsertHere. The first echo should output the content of a custom field. The second should recall the slider with the specific number inserted in the custom field. When trying different possibilities I only get errors.
Can anybody help?
Thank you :)
Don't echo the first value, use it directly inside your second echo.
<?php
echo do_shortcode('[smartslider2 slider="'.get_post_meta($post->ID, 'smartslider2', true).'"]');
?>
Or you can easily put that first value in a variable and use that variable in the second line
<?php $slider = get_post_meta($post->ID, 'smartslider2', true); ?>
<?php echo do_shortcode('[smartslider2 slider="'.$slider.'"]'); ?>
How do you when using custom fields in Wordpress echo just the first value using foreach?
Currently the code is:
<?php for(get_field('venue_event') as $post_object): ?>
<?php echo get_the_title($post_object) ?>
<?php endforeach; ?>
This takes the field from the wordpress page (the field is a link to another page), creates a link to that page using get_permalink but when I want to echo the page title it does it, but then it also echos all other values that are not needed.
If you just want the execute the first iteration of the loop, try this:
<?php foreach(get_field('venue_event') as $post_object): ?>
<?php echo get_the_title($post_object) ?>
<?php break; ?>
<?php endforeach; ?>
Wouldn't it then be easier just to use the first element of the returned array? Maybe Wordpress offers other filters that return the the page's title only.
you can just add
$counter = 0;
<?php for(get_field('venue_event') as $post_object): ?>
$counter++;
if($counter == 1)
{
<?php echo get_the_title($post_object) ?>
}
<?php endforeach; ?>