I have blog post in wordpress for audio podcast like
[audio mp3="http://www.andrewbusch.com/wp-content/uploads/show_6195505.mp3"][/audio]
We talk the latest with forward guidance in the Federal Reserve with Wall Street Journal reporter, Jon Hilsenrath.
I want to make a download link also for the above mp3 url.
How to extract the url from the above content?
I tried like the below but it is not working
<div class="banner-text">
<h1><?php echo the_title(); ?></h1>
<?php the_content(); ?>
<?php
$content = get_the_content( $more_link_text, $stripteaser );
preg_match_all('#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#', $content, $match);
$match = $match[0];
?>
<div class="banner-download"><span class="displace">Download</span></div>
</div>
Any help ?
Interesting question. My instinct would be to use as much of WordPress's built in shortcode functionality as possible to do the work. The get_post_galleries function seems to do something similar. So something like this seems to do what you want:
<?php
// Assumes $content is already set
preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER );
foreach ($matches as $match) {
if ( 'audio' === $match[2] ) {
$tags = shortcode_parse_atts( $match[3] );
echo $tags['mp3'];
}
}
You might need to refine it depending on how you want to handle it if there are multiple audio shortcodes.
Related
I'm looking to move "Submitted By" info from node.tpl to page.tpl however when I add the following from node.tpl I get errors. Im assuming I dont have access to those variables, but would like to know how I can set up a pre-proccess to get it to display as it does in the node.tpl
<?php if ($display_submitted): ?>
<div class="submitted">
<?php print $submitted; ?>
</div>
<?php endif; ?>
You can either use a preprocess function in the template.php of your theme, as explained here:
https://drupal.stackexchange.com/questions/40222/how-can-i-print-node-authors-last-login-date-on-page-tpl-php
In your case it would look like this (tested on Drupal 7):
function yourtheme_preprocess_page(&$variables) {
$variables['author'] = "";
if (isset($variables['node']) && ($account = user_load($variables['node']->uid))) {
$variables['author'] = $account->name;
}
}
And then in your page.tpl.php use this:
Submitted by: <?php print $author; ?>
If you don’t want to touch any of your theme’s files, but you need to output the author’s name in another region as the node content, you could create a view (block display) containing the node author, and assign it to the region.
While normally done in node.tpl.php, if the page is a node view page, the $node variable is also available in page.tpl.php
You can then use something like:
if (isset($node)) {
// Check if display submitted variable is set for this node type
if (variable_get('node_submitted_'. $node->type, 0)) {
// Do stuff
}
}
An alternative approach would be adding the required logic instead to an implementation of
hook_preprocess_page
Bonus update: You can see the $node variable added to page.tpl.php in core template_preprocess_page
if ($node = menu_get_object()) {
$variables['node'] = $node;
}
In page.tpl.php:
<div class="submitted">
<?php echo format_date($node->created, 'custom','d.m.Y'); ?><br />
<?php echo 'by ' . $node->name; ?>
</div>
How can I show the the weight (with units) in product page in 1.5.6.
Example: Weight - 2.5 kg; Weight - 250 mg ...
I've been reading some articles, but nothing working correctly.
You can format weight with Opencart's weight class format() method like this:
$this->weight->format($weight,$weight_class_id);
The getProduct() method already supplies both values you need so you can easily call it from the product controller like so:
$this->data['product_weight'] = $this->weight->format($product_info['weight'],$product_info['weight_class_id']);
Then display $product_weight wherever you want in the tpl as you would any other variable. This will give you exactly what you want but with no space (i.e., '250mg').
If you want more control over the formatting, you can also get only the unit abbreviation (e.g., 'kg', 'oz', 'lb', etc) with the getUnit() method like this:
$this->weight->getUnit($product_info['weight_class_id']);
You could then put them together however you want. If you want a space for instance:
$this->data['product_weight'] = $product_info['weight'] . ' ' . $this->weight->getUnit($product_info['weight_class_id']);
go to catalog/language/english/product/product.php,Find:
$_['text_model'] = 'Product Code:';
Add below code after it
$_['text_weight'] = 'Weight:';
open catalog/controller/product/product.php, Find:
$data['text_stock'] = $this->language->get('text_stock');
Add below code after it:
$data['text_weight'] = $this->language->get('text_weight');
In same file search for the code:
$data['model'] = $product_info['model'];
Paste below code after it:
$data['weight'] = $product_info['weight'];
$tablewunit = $this->db->query("SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE (wcd.weight_class_id = " . $product_info['weight_class_id'] . ") AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "'");
$data['weight_unit'] = $tablewunit->row['unit'];
Now open catalog/view/theme/---yourtheme---/template/product/product.tpl, and find:
<li><?php echo $text_stock; ?> <?php echo $stock; ?></li>
Add below code after it:
<td><b><?php echo $text_weight; ?></b></td>
<td><?php echo round ($weight, 2) . ' ' . $weight_unit; ?></td>
<tr>
<?php if ($weight) { ?>
<tr>
<?php } ?>
Thats all
Hello fellow Bulgarian i assume by your name.
If you want to display weight on products it's very simple.
Open your FTP and go to catalog/view/theme/YOURTHEME/template/product and download product.tpl
find this line
<span class="reward"><small><?php echo $text_points; ?> <?php echo $points; ?></small></span><br />
<?php } ?>
Right after it paste this
<?php
echo round($weight,2). "kg";
?>
(Or paste it where ever you want to see it on the product page.)
after that go to /catalog/controller/product and open product.php
find this line
$this->data['model'] = $product_info['model'];
and right after it paste this line:
$this->data['weight'] = $product_info['weight'];
and you are pretty much done with that.
Hopefully i understood your question correctly.
I'd like to use my product tags as meta keywords on every product page. Can anyone help me with this code?
Thaks
Below are some tips and they are general but give a direction of the different approaches to do this. Step 4 is a bit obvious. I am sorry but this not a module request forum, your question I think is fair so this direction set should get you in the right direction.
1 - Open catalog/view/theme/default/product/product.tpl
And do a find and replace with the header echo:
<?php
$getKeysandReplace=$header;
$getKeysandReplace=str_replace("<meta name=", "");
?>
Understand? Or use a regex to delete the Meta Keyword and Meta Description from the $header string and replace them with your own on the product.tpl - just grab the tags echo in the below code.
<?php if ($tags) { ?>
<div class="tags"><b><?php echo $text_tags; ?></b>
<?php for ($i = 0; $i < count($tags); $i++) { ?>
<?php if ($i < (count($tags) - 1)) { ?>
<?php echo $tags[$i]['tag']; ?>,
<?php } else { ?>
<?php echo $tags[$i]['tag']; ?>
<?php } ?>
<?php } ?>
</div>
<?php } ?>
2 - You can edit header.tpl and do a IF($GET or if page is product type page then display this Meta Tag or display the normal tags.
3 - You can do an SQL crob job that copies the product tags, and places them as product keywords in your database everyday.
4 - Make sure staff copy and paste the tags as keywords to in the admin panel - stating the obvious
In the code below I'd like to show the created date, author and have them be linked but nothing for they do not show. I believe I need to be doing $node-> rather that row, haven't figured out the exact code. Or what if anything I need to change under Views in my Drupal 6 installation. Thanks in advance!
<?php if($node->type == 'blog'): ?>
<div class="blog-page">
<div class="title-post">
<div class="top-image">
<?php print $node->field_image[0]['view'] ?>
</div><!--TOP-IMAGE-->
<p>Posted on ?php $row['created'] ?>, by
<?php print $row['name'] ?></p>
</div>
<div class="content-page">
<?php print $node->content['body']['#value'] ?>
</div>
</div>
<?php else: ?>
<?php print $content ?>
<?php endif ?>
Drupal has a node object with tons of related information in it. Basically if you ever need to use information from it like author, date, title, etc, you can easily determine the code by printing the node object.
echo '<pre>';
print_r($node);
echo '</pre>';
lets say it outputted something like this for simplicity's sake:
stdClass {
nid = 3
content = stdClass {
raw = " ... "
clean = " ... "
}
}
To output those bits of information in your template, you'd write in the following way.
for a field with no subclass:
<?php print $node->nid ?>
for a field with a subclass:
<?php print $node->content['raw'] ?>
Does that make sense? after you get that down, you literally can figure out anything when programming drupal templates.
so, if you wanted to construct a url, you'd just chain it up:
<?php
$nid = $node->nid;
$uri = "some/path".$nid;
print $uri;
?>
I have a code like this
<div class="rgz">
<div class="xyz">
</div>
<div class="ckh">
</div>
</div>
The class ckh wont appear everytime. Can someone suggest the regex to get the data of fiv rgz. Data inside ckh is not needed but the div wont appear always.
Thanks in advance
#diEcho and #Dve are correct, you should learn to use something like the native DOMdocument class rather than using regex. Your code will be easier to read and maintain, and will handle malformed HTML much better.
Here is some sample code which may or may not do what you want:
$contents = '';
$doc = new DOMDocument();
$doc->load($page_url);
$nodes = $doc->getElementsByTagName('div');
foreach ($nodes as $node)
{
if($node->hasAttributes()){
$attributes = $element->attributes;
if(!is_null($attributes)){
foreach ($attributes as $index=>$attr){
if($attr->name == 'class' && $attr->value == 'rgz'){
$contents .= $node->nodeValue;
}
}
}
}
}
Regex is probably not your best option here.
A javascript framework such as jquery will allow you to use CSS selectors to get to the element your require, by doing something like
$('.rgz').children().last().innerHTML