I am trying to combine a code used to pull name of a store for my site with a word, and it is seperating the store name and word and not forming a hyperlink.
For example it will read..............6pm deals, but only hyperlink the store name, here is code that pulls the store name........
<div class="store-name">
<?php echo get_the_term_list($post->ID, APP_TAX_STORE, ' ', ', ', ''); ?>
</div>
I want it to say 6pm deals and hyperlink entire term.
<div class="store-name"><?php echo get_the_term_list($post->ID, APP_TAX_STORE, ' ', ', ', ''); ?>.....6pm deals</div>
Related
I wanted to display the weather from a user on my website with openweathermap. that works with the temperatures so far i wanted to display whether it is raining or cloudy that doesn't work. weather->main doesn't work can someone help me?
Here is my code
$url="http://api.openweathermap.org/data/2.5/forecast?q=".$city.",".$land."&APPID=MYAPPIDf&units=metric";
$json=file_get_contents($url);
$data=json_decode($json);
echo '<p>Temperature from: ', $data->city->name, ' (', $data->city->country, ')</p>';
// the general information about the weather
echo '<p><strong>Current:</strong> ', $data->list[0]->main->temp, '° C</p>';
echo '<p><strong>Min:</strong> ', $data->list[0]->main->temp_min, '° C</p>';
echo '<p><strong>Max:</strong> ', $data->list[0]->main->temp_max, '° C</p>';
echo '<p><strong>Fells Like:</strong> ', $data->list[0]->main->feels_like, '° C</p>';
echo '<p><strong>actualy Weather:</strong> ', $data->list[0]->weather->main, '</p>';
?>
that's what it shows me on my website
ErrorImage
I've tried a few things but I can't do it myself
weather is an array, you must use an index to access the properties of one element :
echo $data->list[0]->weather[0]->main ;
Also, remove your API key from your question.
So I am trying to figure out how I can:-
Remove all white-space; and
Remove all other characters e.g. ()
I have a phone number which is pulled from user profile and I wish to make this a clickable link.
OLD:
<div class="phone heading-font"><?php echo esc_attr($user_fields['phone']); ?></div>
NEW:
<?php echo esc_attr($user_fields['phone']); ?>
Problem is if user enters their number as (03) 1234 1234 it won't work unless I remove whitespace and the () area code fields.
I wasn't sure how I could use trim with esc_attr?
Use str_replace() like below:-
str_replace(array( '(', ')',' ' ), '', esc_attr($user_fields['phone']);
Like:-
<?php echo esc_attr($user_fields['phone']); ?>
Example:- https://eval.in/753919
I am writing an application that will look at a single record, obtain values from about 12 flags (0 or 1), look up those flags against a status table (in MySQL) and return a variable called $status_message which is in that table.
In this table I need to have hyperlinks (working fine) but also echo some variables, i.e.
You have no bids for {{$row->_item_name}}
or
View this item now by clicking here
Now I need item name and the other example to be translated into <?php echo $row->_item_name; ?>
I have tried a preg_replace with the following:
<?php
$find = array('/{{/', '/}}/');
$replace = array('<?php echo ', ' ?>');
echo preg_replace($find, $replace, $status_message);
?>
but this is not working.
Can anyone advise how I can get the desired result and 'echo' the variable in the MySQL field?
Had a brainwave. Much simpler,
instead of $row->_item_name I just put {{itemname}} in the string. I then use the following code:
<?php
$message_buyer = str_replace('{{itemname}}', $row->_item_name , $message_buyer);
echo $message_buyer;
?>
so no need to have <?php calls in the string at all.
I have a list of items that a user can select from when listing their house. I then display these on the frontend using the following:
<? if($group[property_amenities] != "") { ?>
<hr>
<h2 class="vmargin">Amenities</h2>
<?php echo $group[property_amenities]; ?>
<? } ?>
The issues is that I believe I don't have access to change the HTML and the items are listed as follows:
Amenities
Open Plan,Carpeted Floors,
How can I modify the above code to display the items in separate rows, as well as remove the "," or replace the "," with something like " - "
Use str_replace to replace all the commas with break tags, or dashes, or whatever you want.
<?php echo str_replace(',', '<br>', $group[property_amenities];) ?>
I'm needing to replace white spacing with a plus sign "+" for the code displayed below.
I'm in the process of modifying some code which generates the label and url for products displayed in my catalog. The problem I face is that my current code doesn't do the replacement. Can someone please modify the code, replacing a spacing for a plus sign "+".
<h5><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h5>
and will return a url something like this:
http://www.efficienttrade.co.nz/catalogsearch/result/?order=relevance&dir=desc&q=potassium nitrate
However, when getName() function is used, names which have a space don't work for the generated search query. So I need to replace the space with a "+" to make the search query url work.
Thanks
As far as i understand your problem, you need to replace spaces by hypens in your product name. This can be achieved by replacing the following code in your href
...<?php echo $this->stripTags($_product->getName(), null, true); ?>...
with
...<?php echo str_replace(' ', '-', $this->stripTags($_product->getName(), null, true)); ?>...
How about the following to make you code slightly nicer (although PHP/HTML soup is never a lot of fun). The first line of PHP is the one that replaces spaces with hyphen
<?php
/*Get product name, stripped of HTML and spaces*/
$productName = str_replace(' ', '-', strip_tags($_product->getName(), null, true));
/*Assign variables rather than using same function multiple times.*/
$productAttribute = $_helper->productAttribute($_product, $_product->getName(), 'name');
/*Concatenate the URL here for easier code fixing later.*/
$url = 'http://www.efficienttrade.co.nz/catalogsearch/result/order=relevance&dir=desc&q=' . $productName;
?>
<h5>
<?php echo $productAttribute ?>
</h5>