I'm trying to have my echo results on the same line after being ran on the page. The code below works, but displays the price on one line, price with discount on the next, and the button on another.
<strike>$<?php echo number_format($row->price,2);?> USD</strike>
<h3>$<?php
$sale_price = $row->price -(($row->price /100) * $row->discount);
echo number_format($sale_price,2);
?> USD
</h3>
<button type="submit" class="btn btn-success">
<span class="glyphicon glyphicon-shopping-cart"></span> <b>View Product</b>
</button>
Anyone have suggestions to make it all on the same line so their right next to each other? I'm sure its a simple fix, but I've tried researching and haven't come across something yet.
Thank you!
Try something like this:
<?php
$sale_price = $row->price - (($row->price /100) * $row->discount);
echo "<h3><strike>" . number_format($row->price,2) . " USD </strike> " . number_format($sale_price,2) . " USD</h3>";
?>
or this perhaps:
$<?php $sale_price = $row->price - (($row->price /100) * $row->discount);?>
<h3><strike>$<?php echo number_format($row->price,2);?> USD </strike>$<?php echo number_format($sale_price,2);?> USD</h3>
The problem is mostly in the place where you use the <h3> tags, and because you have put the original price outside of that tag.
Use css, i.E.:
strike, h3 { float: left; }
The problem is the usage of "h3" It's breaking the line. It always does.
Copy that style into a class and use a "span class='h3class'" instead.
That will solve your problem.
Related
I have this snippet of html:
<li class="result-row" data="2">
<p class="result-info">
<span class="icon icon-star" role="button">
<span class="screen-reader-text">favorite this post</span>
</span>
<time class="result-date" datetime="2018-12-04 09:21" title="Tue 04 Dec 09:21:50 AM">Dec 4</time>
Link Text
and this perl code (not production, so no quality comments are necessary)
my $root = $tree->elementify();
my #rows = $root->look_down('class', 'result-row');
my $item = $rows[0];
say $item->dump;
my $date = $item->look_down('class', 'result-date');
say $date;
my $title = $item->look_down('class', 'result-title hdrlnk');
All outputs are as I expected except $date isn't defined.
When I look at the $item->dump, it looks like the time element doesn't show up in the output. Here's a snippet of the output from $item->dump where I would expect to see a <time...> element. All it shows is the text from the time element.
<li class="result-row" data="2"> #0.1.9.3.2.0
<a class="result-image gallery empty" href="https://localhost/1.html"> #0.1.9.3.2.0.0
<p class="result-info"> #0.1.9.3.2.0.1
<span class="icon icon-star" role="button"> #0.1.9.3.2.0.1.0
" "
<span class="screen-reader-text"> #0.1.9.3.2.0.1.0.1
"favorite this post"
" "
" Dec 4 "
<a class="result-title hdrlnk" data="2" href="https://localhost/1.html"> #0.1.9.3.2.0.1
.2
"Link Text..."
" "
...
I've not used HTML::Element before. I rtfmed and didn't see any tag exclusions and I did a search of the package code for tags white/black lists (which wouldn't make sense, but neither does leaving out the time tag).
Does anyone know why the time element is not showing up in the dump and any search for it turns up nothing?
As an fyi, the rest of the code searches and finds elements without issue, it just appears to be the time tag that's missing.
HTML::TreeBuilder does not support HTML5 tags. Consider Mojo::DOM as an alternative that keeps up with the living HTML standard. I can't show how your whole code would look with Mojo::DOM since you've only shown a piece, but the Mojo::DOM equivalent of look_down is find (returns a Mojo::Collection arrayref) or at (returns the first element found or undef), both taking a CSS selector.
I need help to create space between two buttons on my blog, one for previous post, one for next. Both buttons appear one next to another, i need to be in the right and left corner. This is the code for them:
<?php
$prev_post = get_previous_post();
if (!empty( $prev_post )): ?>
<a class="post-nav-prev" title="<?php _e('Previous post:', 'baskerville'); echo ' ' . esc_attr( get_the_title($prev_post) ); ?>" href="<?php echo get_permalink( $prev_post->ID ); ?>"><?php _e('Previous post', 'baskerville'); ?></a>
<?php endif; ?>
<?php
$next_post = get_next_post();
if (!empty( $next_post )): ?>
<a class="post-nav-next" title="<?php _e('Next post:', 'baskerville') ; echo ' ' . esc_attr( get_the_title($next_post) ); ?>" href="<?php echo get_permalink( $next_post->ID ); ?>"><?php _e('Next post', 'baskerville'); ?></a>
<?php endif; ?>
<?php edit_post_link( __('Edit post', 'baskerville')); ?>
<div class="clear"></div>
I honestly tried to run your code snippet locally, but just couldn't get it to work so I will do my best and help you achieve what you want.
But before I get started, make sure you don't post PHP snippets in a post that has nothing to do with PHP. If you were to only post the HTML code, it would have made things much easier.
So I see you have two a elements which you are using as buttons. You don't want them next to each other but "in the right and left corner" Although I'm not sure whether you mean the corners of the page or the corners of where those buttons might or might not be, here is how I would tackle this problem.
#navigationControls{
width:300px;
height:20px;
}
<div id="navigationControls">
<a class="post-nav-prev" title="test">Previous</a>
<a class="post-nav-next" style="float:right" title="test">Next</a>
</div>
By putting them in a container with a defined width, we can float the next button to the right of the container. You can modify the containers width to how big you want it to be.
Please let me know if my answer got you in the right direction and if you need any help!
I am using this code to store HTML code in a variable called $conversions
$conversions = "GBP " . number_format($file*0.84) . "CHF " . number_format($file*1.23)
However I can't seem to figure out how to add a <br> before the word "CHF ".
Any ideas?
The whole code is as follows:
<?php
$file = get_field('fl_price');
if(trim($file) == ""){echo 'Price on Application' ;}else{$conversions = "GBP " . number_format($file*0.84) . "<br />CHF " . number_format($file*1.23) ;echo 'EUR ' . number_format($file) . "</br><a class=\"wp-tooltip\" title=\" $conversions \">Other Currencies</a>" ;}
?>
$conversions = "GBP " . number_format($file*0.84) . "
CHF " . number_format($file*1.23);
Echoing $conversions will now have a HTML-linebreak before CHF.
You are adding your string to an attribute of <a> called title. This isn't going to be displayed and is certainly not going to render any HTML (like a br tag).
edit:
As per OptimusCrime's suggestion, this does work:
http://jsfiddle.net/5rM4u/1/
Replace your <br/> with
and you're good to go.
You are trying to print the $conversions variable in the "title" of the "a" tag. just using <br /> will not work.
See some of the answers to this question "How can I use a carriage return in a HTML tooltip?" it may contain the answer that you are looking for.
I need to add a spantag to an h1 heading in wordpress. I tried writing in through the CMS but it renders the spantag as text.
The site's title is a name and I want to give different styles to the words.
Suggestions?
Following David Thomas's advice I've written this: but it appends the span last and empty.
<h1>
<a href="<?php bloginfo('url'); ?>/">
<?php
$completeName = bloginfo('name');
$split = explode(" ",$completeName);
echo $split[0]."<span>".$split[1]."</span>"
?>
</a>
</h1>
You should be using get_bloginfo as Felipe suggested, but still pass in the 'name' parameter.
I was just working on the same code for the same reason and thought I should post for future visitors:
<?php
$completeName = get_bloginfo('name');
$nameParts = explode(" ", $completeName);
echo '<span>'.$nameParts[0].'</span> '.$nameParts[1];
?>
Apply the style to the h1 instead.
By the way, you probably want to edit the theme.
What about:
<? echo get_bloginfo('name', 'raw'); ?>
Can't test it for now, but here's the documentation about it:
bloginfo()
==> it just echoes the result of get_bloginfo() and there's a second parameter to this function
==> wptexturize(), a function that WON'T be called so beware!
Nope. Ignore this. The space is put there by browser.
This is a HTML snippet from my application:
Correct answers:
0 / 6<br /><br />
You have failed to pass the final test.
<a href="/module/controller/course/id/5" class="accessible-link">
Click here
</a>
to return to the training.
As you can see, there is a single space after the </a> closing tag. Yet in the browser the space is added inside the anchor. So it looks like this:
This is the PHP code which produces the HTML:
<?php if (isset($this->correctAnswersCount) && isset($this->answersCount)): ?>
<?php echo Zend_Registry::get('translate')->_('Počet správnych odpovedí'); ?>:
<?php echo ToHtml($this->correctAnswersCount); ?> / <?php echo ToHtml($this->answersCount); ?><br /><br />
<?php endif; ?>
<?php echo Zend_Registry::get('translate')->_('Záverečný test sa vám nepodarilo úspešne absolvovať.'), "\n"; ?>
<a href="<?php echo ToHtml($this->backToCourseUri); ?>" class="accessible-link">
<?php echo Zend_Registry::get('translate')->_('Kliknite'), "\n"; ?>
</a>
<?php echo Zend_Registry::get('translate')->_('pre návrat do kurzu.'), "\n"; ?>
I am completely baffled by this and cannot figure out what's causing this even though I've been staring into the code for 30 minutes now.
This is a relevant part from the translation file:
'Kliknite' => 'Click here',
As you can see, there should be no space added by Zend_Translate.
Change this:
<a href="<?php echo ToHtml($this->backToCourseUri); ?>" class="accessible-link">
<?php echo Zend_Registry::get('translate')->_('Kliknite'), "\n"; ?>
</a>
Into this:
<a href="<?php echo ToHtml($this->backToCourseUri); ?>" class="accessible-link">
<?php echo Zend_Registry::get('translate')->_('Kliknite'), "\n"; ?></a>
The </a> should be in the same line after the <?php echo Zend_Registry::get('translate')->_('Kliknite'), "\n"; ?> aka Click Here
EDIT:
The new line and the spaces after it renders like 1 space that is still inside de <a></a> tags, that is where the blank space is coming from.
EDIT2:
For the record I also don't like the closing tag to be next to the content instead of a being in a new line but that's how it has to be done in order to work correctly.
I like good formatted code and I always look for a autoformat command in my IDE.
But at least for example in Visual Studio when you hit Ctrl + K, Ctrl + D (the Format Document shorcut) the closing tags like the </a> are not automatically moved to a new line for this exact reason: that it should not break the way it looks before the auto format.
Close the 'a' tag directly after the next, without a newline, like this:
Click here
Try it like this:
Click here
I am not sure if this will work, but it is worth trying.
Put immediately after the </a> tag.