how can i echo just the salesPrice without creating a pricediv? I have tried echo salesPrice but that doesn't seem to be working.
<?php echo "<span class='priceColor2'>" . $this->currencyDisplay->createPriceDiv ('salesPrice', '', $this->cart->pricesUnformatted, FALSE) . "</span>" ?>
the code currently echos the price in a separate div like this:
<span class='priceColor2'><div class="PricesalesPrice" style="display : block;" ><span class="PricesalesPrice" >£20.00</span></div></span>
try this...
<?php echo "<span class='priceColor2'>" . strip_tags($this->currencyDisplay->createPriceDiv ('salesPrice', '', $this->cart->pricesUnformatted, FALSE)) . "</span>" ?>
Related
I do know how to add horizontal line in html by using <hr> but I am not sure how to do in php.
My code:
echo '<div class="grid">';
echo '<p>' . $row["title"] . '</p>';
echo '</div>';
I want a line here like (________________) on the website after the $row["title"]
I tried doing this:
echo <hr style="width:50%; text-align:left;margin-left:0">;
But it doesn't seem to work. How can I add the horizontal line? Also, I would like to style it with a color, so something like a colored horizontal line such as yellow or any color?
Try the changes below
Change this:
echo '<div class="grid">';
echo '<p>' . $row["title"] . '</p>';
echo '</div>';
To this:
echo '<div class="grid">' . '<p>' . $row["title"] . '</p>' . '</div>';
echo '<hr/>';
This should work depend on your parent container width.
More how to use this break you can find here: HTML <hr> Tag
I'm trying to put a link around my excerpts like on my titles but i'm getting a parse-error on this line:
echo '<div class="excerpt">''' . nectar_excerpt($excerpt_length) . '</div>';?>
Here the whole code of my post-element:
<div class="post-header">
<h3 class="title">
<?php the_title(); ?>
</h3>
<span class="meta-author"><?php the_author_posts_link(); ?> </span>
<span class="meta-category"> | <?php the_category(', '); ?> </span>
<span class="meta-comment-count"> | <a href="<?php comments_link(); ?>">
<?php comments_number( esc_html__( 'No Comments','salient'), esc_html__( 'One Comment','salient'), '% '. esc_html__( 'Comments','salient') ); ?></a>
</span>
</div>
<?php
$excerpt_length = ( !empty( $nectar_options['blog_excerpt_length'] ) ) ?
intval( $nectar_options['blog_excerpt_length'] ) : 30;
echo '<div class="excerpt">''' . nectar_excerpt($excerpt_length) . '</div>';?>
<div class="meta-tags"> <?php the_tags(''); ?> </div>
<div class="tags-divider"></div>
In PHP, text strings are merged using the dot character. So if you want to connect them together, you should do this:
$a = "text1";
$b = "text2";
echo ($a . $b); // prints "text1text2"
Or in your case like this:
echo "text1" . function() . "text3"; // prints text1text2text3
And if you are using function like string, you don't use the ";" character at the end, because it will end the whole line of code.
echo "text1" . "text2"; . "text3"; // wrong
echo "text1" . "text2" . "text3"; // correct
echo "text1" . function(); . "text3"; // wrong
echo "text1" . function() . "text3"; // correct
So, just add the dots and remove the semicolon, and it should work.
echo '<div class="excerpt">' . '' . nectar_excerpt($excerpt_length) . '</div>';?>
Give this a try?
echo '<div class="excerpt">' . nectar_excerpt($excerpt_length) . '</div>';
Here is the problem that while looping the php in while loop in w3-row-padding of w3 responsive layout . The layout breaks
Here is the source code
<?php
$r=0;
while($r<ceil($fetch_row_count/4))
{ ?>
<div class="w3-row-padding w3-padding-16 w3-center" style="clear:both" id="food">
<?php
while($row=mysqli_fetch_array($res))
{
?>
<div class="w3-quarter">
<img src="admin/uploads/<?php echo $row['image']; ?>" alt="noodles" style="width:50%">
<h3><?php echo $row['title']; ?></h3>
<p><?php echo $row['description']; ?> </p>
</div>
<?php
}
$r++;
}
?>
</div>
Thanks for reply and comments in advance
That bottom div was not being added for each of your padded containers.
The way the code is written you are adding a padded container and then adding your w3-quarter div for each of your result sets and then repeating that a bunch of times with what looks like to me the same set of data in each one.
What you are probably trying to accomplish is just making one padded div and then echo out your result set with the w3-quarter divs inside of it.
Here is your original way with the bottom div corrected:
<?php
$r=0;
while($r<ceil($fetch_row_count/4)) {
echo
'<div class="w3-row-padding w3-padding-16 w3-center" style="clear:both" id="food">';
while($row=mysqli_fetch_array($res)){
echo
'<div class="w3-quarter">' .
'<img src="admin/uploads/' . $row['image'] . '" alt="noodles" style="width:50%">' .
'<h3>' . $row['title'] . '</h3>' .
'<p>' . $row['description'] . '</p>' .
'</div>';
}
$r++;
echo
'</div>';
}
?>
Here is the way I think you are trying to do it: (Just guessing)
<?php
echo
'<div class="w3-row-padding w3-padding-16 w3-center" style="clear:both" id="food">';
$r = 0;
while($row=mysqli_fetch_array($res)){
echo
'<div class="w3-quarter">' .
'<img src="admin/uploads/' . $row['image'] . '" alt="noodles" style="width:50%">' .
'<h3>' . $row['title'] . '</h3>' .
'<p>' . $row['description'] . '</p>' .
'</div>';
$r++;
//I would not actually try to control how many results you add like this.
//I would get the results from a better formatted query.
if($r < ceil($fetch_row_count/4)){
break;
}
}
echo
'</div>';
?>
I have the following code in place, however, I have to strip away all the styling (any css) and have it return rather than echo, otherwise it messes up with some other code I'm using.
The other code I'm using echo's a shortcode that outputs the following determined by if there is items in the cart or not.
Obviously I can't echo (on the echo shortcode end of things), so I must return. If the cart is empty, it returns just fine as per my commented code below. It is when the cart has items, I can't get it to return :( my attempt is below.
//Original code, if there's items
if(is_object($cart) && $cart->countItems()) {
?>
<div id="Cart66scCartContents" style="float:right; text-align: right;">
<a id="Cart66scCartLink" href='<?php echo get_permalink($cartPage->ID) ?>'>
<span id="Cart66scCartCount"><?php echo $cart->countItems(); ?></span>
<span id="Cart66scCartCountText"><?php echo $cart->countItems() > 1 ? ' items' : ' item' ?></span>
<span id="Cart66scCartCountDash">–</span>
<!-- <span id="Cart66scCartPrice"><?php //echo CART66_CURRENCY_SYMBOL .
number_format($cart->getSubTotal() - $cart->getDiscountAmount(), 2); ?> -->
</span></a>
<a id="Cart66scViewCart" href='<?php echo get_permalink($cartPage->ID) ?>'>View Cart</a>
<span id="Cart66scLinkSeparator"> | </span>
<a id="Cart66scCheckout" href='<?php echo get_permalink($checkoutPage->ID) ?>'>Check out</a>
</div>
<?php
}
else {
//My code, if there's no items (which works perfectly as a return)
$emptyMessage = isset( $attrs['empty_msg'] ) ? $attrs['empty_msg'] : 'Your cart is empty';
return "<p id=\"Cart66scEmptyMessage\" style=\"float:right; text-align: right;\">" . $emptyMessage . "</p>";
}
My attempt on setting the "if there's items in the cart" to a return rather than echo..
if(is_object($cart) && $cart->countItems()) {
return "<a href='" . get_permalink($cartPage->ID) . "'>" . $cart->countItems(); . " " . $cart->countItems() > 1 ? ' items' : ' item' . "–" . number_format($cart->getSubTotal() - $cart->getDiscountAmount(), 2); . "</a> <a href='" . get_permalink($cartPage->ID) . "'>View Cart</a> | <a href='" . get_permalink($checkoutPage->ID) . "'>Check out</a>";
}
else {
$emptyMessage = isset( $attrs['empty_msg'] ) ? $attrs['empty_msg'] : 'Your cart is empty';
return "<p id=\"Cart66scEmptyMessage\" style=\"float:right; text-align: right;\">" . $emptyMessage . "</p>";
}
The text "1 item – View Cart | Check out" is not showing up with my attempt.
What have I done wrong?
Thank you!!
You have a semicolon at . $cart->countItems();, remove that and you should be good to go
Try to use HEREDOC
For example:
if (is_object($cart) && $cart->countItems()) {
$items = $cart->countItems() > 1 ? ' items' : ' item';
return <<<HTML
<div id="Cart66scCartContents" style="float:right; text-align: right;">
<a id="Cart66scCartLink" href='{get_permalink($cartPage->ID)}'>
<span id="Cart66scCartCount">{$cart->countItems()}</span>
<span id="Cart66scCartCountText">{$items}</span>
<span id="Cart66scCartCountDash">–</span>
</span></a>
<a id="Cart66scViewCart" href='{get_permalink($cartPage->ID)}'>View Cart</a>
<span id="Cart66scLinkSeparator"> | </span>
<a id="Cart66scCheckout" href='{get_permalink($checkoutPage->ID)}'>Check out</a>
</div>
HTML;
}
else {
$emptyMessage = isset( $attrs['empty_msg'] ) ? $attrs['empty_msg'] : 'Your cart is empty';
return "<p id=\"Cart66scEmptyMessage\" style=\"float:right; text-align: right;\">" . $emptyMessage . "</p>";
}
Maybe
$html = <<<EOD
<tr>
<td>TEST</td>
</tr>
EOD;
Would help here?
Declare the string variable and concatenate all the HTML you trying to echo in that string and return the string variable .
Example $string = '
I'm currently using the following PHP foreach code below. When I view the source code, it's a giant block of list items.
My question is, how can I edit this so each list item in the source code is on it's own line for easier debugging?
foreach($xml->Event as $event) {
echo '<li><a href="', $event->link, '">';
echo '<strong>', $event->title, '</strong>';
echo '<span>', $event->beginDate, ' at ', $event->beginTime, '</span>';
echo $event->location;
echo '</a></li>';
}
Like this:
foreach($xml->Event as $event) {
echo '<li><a href="', $event->link, '">';
echo '<strong>', $event->title, '</strong>';
echo '<span>', $event->beginDate, ' at ', $event->beginTime, '</span>';
echo $event->location;
echo '</a></li>' . "\n";
}
Just add . "\n" to the last line in your loop.
Use new line '\n' or PHP_EOL at end of each line
Try modifying the final line to include a line break:
echo '</a></li>' . PHP_EOL;
Append all of your strings with either "\n" (make sure you use double-quotes), or PHP_EOL.
echo '</a></li>' . "\n";
// or
echo '</a></li>' . PHP_EOL;
Use \n.
foreach($xml->Event as $event) {
echo '<li><a href="', $event->link, '">' . "\n";
echo '<strong>', $event->title, '</strong>' . "\n";
echo '<span>', $event->beginDate, ' at ', $event->beginTime, '</span>' . "\n";
echo $event->location . "\n";
echo '</a></li> . "\n"';
}
I would write the code like this:
<?php foreach($xml->Event as $event) { ?>
<li>
<a href="<?php echo $event->link; ?>">
<strong><?php echo $event->title; ?></strong>
<span><?php echo $event->beginDate; ?> at <?php echo $event->beginTime; ?></span>
<?php echo $event->location; ?>
</a>
</li>
<?php } ?>
Add a '\n' at the end of each line you want to break.
foreach($xml->Event as $event) {
echo '<li><a href="', $event->link, '">\n';
echo '<strong>', $event->title, '</strong>\n';
echo '<span>', $event->beginDate, ' at ', $event->beginTime, '</span>\n';
echo $event->location;
echo '</a></li>' . "\n";
}