Display youtube iframe if url stored in mySQL - mysql

I created a form where we can register youtube embed url in a post.
I'd like to display the iframe only if an url has been register for this post.
I made this code to display the report information :
<?php
$req = $db->query('SELECT id, title, author, category, date_event, country, city, content, tag, youtube FROM report ORDER BY date_creation DESC LIMIT 0, 10');
while ($data = $req->fetch())
{
?>
<div class="news">
<h3><?php echo htmlspecialchars($data['title']); ?></h3>
<p>Author: <?php echo htmlspecialchars($data['author']); ?></p>
<p>Category : <?php echo htmlspecialchars($data['category']); ?></p>
<p>Date of the event : <?php echo htmlspecialchars($data['date_event']); ?></p>
<p>Country : <?php echo htmlspecialchars($data['country']); ?></p>
<p>City : <?php echo htmlspecialchars($data['city']); ?></p>
<p class="display_list"><?php echo html_entity_decode($data['content'], ENT_HTML5 , 'UTF-8'); ?></p>
<p>Tag : <?php echo htmlspecialchars($data['tag']); ?></p>
<p>Youtube : <?php echo htmlspecialchars($data['youtube']); ?></p>
<p>
<?php
$youtube=$data['youtube'];
if($youtube==1){
echo "<p>display iframe</p>";
}else{
{
echo "<p>don't display iframe</p>";
}
}
?>
</p>
The request to display url with works correctly. the urls are displayed if they are contained in the row.
However the condition code displays the same answers for all the posts : "don't display iframe".
The condition statement for $youtube variable is certainly not right but I can't figure out the issue.

you have assigned $youtube=1; instead of $youtube=$data['youtube']; in the code
try this
<?php
$req = $db->query('SELECT id, title, author, category, date_event, country, city, content, tag, youtube FROM report ORDER BY date_creation DESC LIMIT 0, 10');
while ($data = $req->fetch())
{
?>
<div class="news">
<h3><?php echo htmlspecialchars($data['title']); ?></h3>
<p>Author: <?php echo htmlspecialchars($data['author']); ?></p>
<p>Category : <?php echo htmlspecialchars($data['category']); ?></p>
<p>Date of the event : <?php echo htmlspecialchars($data['date_event']); ?></p>
<p>Country : <?php echo htmlspecialchars($data['country']); ?></p>
<p>City : <?php echo htmlspecialchars($data['city']); ?></p>
<p class="display_list"><?php echo html_entity_decode($data['content'], ENT_HTML5 , 'UTF-8'); ?></p>
<p>Tag : <?php echo htmlspecialchars($data['tag']); ?></p>
<p>
<?php
$youtube=$data['youtube'];
if($youtube==1){
echo "<p>display iframe</p>";
}else{
{
echo "<p>don't display iframe</p>";
}
}
?>
</p>

Related

how to style a particular wordpress sidebar widget

I have sidebar widgets visible when I open a post in my website. But since the website is bilingual, some of them are supposed to be right aligned while others left aligned.
Is this possible? If I knew which function is generating the content for sidebar HTML, perhaps I could achieve this but I don't know where that function is, if it existed.
umm... kinda got it working.
I made the following changes to the file:
wp-includes\widgets\class-wp-widget-recent-posts.php
It had the following code:
<ul>
<?php while ( $r->have_posts() ) : $r->the_post(); ?>
<li>
<?php get_the_title() ? the_title() : the_ID(); ?>
<?php if ( $show_date ) : ?>
<span class="post-date"><?php echo get_the_date(); ?></span>
<?php endif; ?>
</li>
<?php endwhile; ?>
</ul>
I then changed it to:
<ul>
<?php while ( $r->have_posts() ) : $r->the_post(); ?>
<?php
if (strpos(get_the_title(), 'a') !== false) {
echo '<li class="engwidget">';
}else{
echo '<li class="localwidget">';
}
?>
<?php get_the_title() ? the_title() : the_ID(); ?>
<?php if ( $show_date ) : ?>
<span class="post-date"><?php echo get_the_date(); ?></span>
<?php endif; ?>
</li>
<?php endwhile; ?>
</ul>
I've achieved what I wanted but no idea if this is by any means a right way to do so.

Magento is not updating Shipping cost on changing the Shipping method radio button

I change the shipping method as you can see in the screenshot but magento does not refresh the inner page with the calculated total shipping cost.I think this is a bug in version 1.9. Here you can see the screenshot .Magento ver. 1.9.2.4
When I change the radio button from one shipping method the onestepcheckout does not refresh the inner page with calculated cost.
How can I refresh the inner page with javascript.
Thanks
Add the below code in available.phtml file
<?php if (!($_shippingRateGroups)): ?>
<strong><?php echo Mage::helper('oscheckout')->__('Sorry, no quotes are available for this order at this time.') ?></strong>
<?php else: ?>
<dl class="shipment-methods">
<?php $methodcount = count($_shippingRateGroups); $check_default = 1; foreach ($_shippingRateGroups as $code => $_rates): ?>
<dd><?php echo $this->getCarrierName($code) ?></dd>
<?php foreach ($_rates as $_rate): ?>
<dt style="margin-bottom: 5px;">
<?php if ($_rate->getErrorMessage()): ?>
<ul class="messages"><li class="error-msg"><ul><li><?php echo $_rate->getErrorMessage() ?></li></ul></li></ul>
<?php else: ?>
<input <?php echo $check_default == 1 ? 'checked="checked"':'' ?> name="shipping_method" type="radio" class="validate-one-required-by-name" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>" />
<label for="s_method_<?php echo $_rate->getCode() ?>"> <?php echo $_rate->getMethodTitle() ?>
<strong>
<?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
<?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
<?php echo $_excl; ?>
<?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
(<?php echo Mage::helper('oscheckout')->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
<?php endif; ?>
</strong>
</label>
<?php endif ?>
</dt>
<?php endforeach; $check_default++; ?>
<?php endforeach; ?>
</dl>
<?php endif;
?>
Add this script in the same file
<script type="text/javascript">
<?php if($methodcount >= 1): ?>
document.observe('dom:loaded', function(){
shipping.loadReview();
var payment_methods = $('ajax-payment-methods');
//payment_methods.update('<div class="ajax-load"> </div>');
payment.reloadPaymentBlock();
// reloadPaymethod();
});
<?php endif; ?>
$$('dl.shipment-methods input').invoke('observe', 'click', function() {
shipping.loadReview();
var payment_methods = $('ajax-payment-methods');
//payment_methods.update('<div class="ajax-load"> </div>');
payment.reloadPaymentBlock();
// reloadPaymethod();
});
</script>

How to show the message “No Products” when there's no products in my custom block?

I need to show the message "No Products" or "There are no products matching the selection" when there's nothing to show in my block.
<?php
$manufacturer = Mage::registry('current_product')->getMerchantName();
$productCollection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('merchant_name',$manufacturer);
$productCollection->getSelect()->order('RAND()');
$productCollection->getSelect()->limit(5);
foreach ($productCollection as $_product)
?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(228) ?>" width="228" height="228" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
<div class="product-details">
<p class="product-name"><?php echo $this->htmlEscape($_product->getName()) ?></p>
<?php
$merchant_name = $_product->getAttributeText('merchant_name');
if ($merchant_name){?>
<div>by <?php echo $merchant_name;?> </div>
<?php }
else if ($_product->getIsEbayaffiliate()) { ?>
<div>by eBay</div>
<?php }
else { ?>
<div>by Home Done</div>
<?php } ?>
Also I need to add getPriceHtml to the above code to show the product price.
I have tried <?php echo $this->getPriceHtml($_item, true) ?>
There you go:
(Advice: use closed tags like <?php if(): ?> for better readability)
<?php if(is_array($productCollection) && count($productCollection) ): ?>
<?php foreach ($productCollection as $_product): ?>
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(228) ?>" width="228" height="228" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
<div class="product-details">
<p class="product-name"><?php echo $this->htmlEscape($_product->getName()) ?></p>
<?php $merchant_name = $_product->getAttributeText('merchant_name'); ?>
<?php if ($merchant_name):?>
<div>by <?php echo $merchant_name;?> </div>
<?php elseif($_product->getIsEbayaffiliate()): ?>
<div>by eBay</div>
<?php else: ?>
<div>by Home Done</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
<?php else: ?>
// here goes whatever you want to display if no products found in list
<?php endif; ?>

How do I echo the each posts category in wordpress

I am looking to make wordpress print/echo the category name of a post into it's class. I need this to work on the index page inside the main loop. Here is what I mean:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article class="<?php ** I NEED THIS CODE ** ?>">
<div>
<h2><?php the_title(); ?></h2>
</div>
<?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } else {} ?>
</article>
<?php endwhile; ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
Hopefully you understand my poor description of my issue. Thanks
From http://lorelle.wordpress.com/2007/09/06/using-wordpress-categories-to-style-posts/
Add the following to your theme's functions.php file:
function the_category_unlinked($separator = ' ') {
$categories = (array) get_the_category();
$thelist = '';
foreach($categories as $category) { // concate
$thelist .= $separator . $category->category_nicename;
}
echo $thelist;
}
And the corresponding markup would be:
<article class="<?php the_category_unlinked(' '); ?>">

Wordpress category, get all its posts

I am currently finish of my theme for a wordpress website that I am building, I am having a problem getting my categories to work though.
I am lost as to how I can loop through the current category if I am at a URL of say "/category/category-name" how would I loop the posts that belong to the category "category name".
I I do the following on my template
<p>Category: <?php single_cat_title(); ?></p> I get the following output
Category Name
So how do I loop through that categories posts?
Category.php
<?php get_header(); ?>
<article class="content">
<section class="top">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
</section>
<section class="middle">
</section>
</article>
<?php get_footer(); ?>
page-news.php
<?php get_header(); ?>
<article id="content">
<section class="top">
<?php query_posts('post_type=news'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<section class="news">
<?php the_post_thumbnail(); ?>
<h2><?php echo strtolower(the_title()); ?></h2>
<span class="posted"><?php the_date("l jS M Y"); ?></span>
<?php
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
?>
<p><?php echo substr(strip_tags($content), 0, 400).'…' ; ?>Read More</p>
<p class="tags">
<strong>Categories:</strong>
<?php
$post_categories = wp_get_post_categories( $post->ID );
$cats = array();
foreach($post_categories as $c){
$cat = get_category( $c );
$cats[] = array( 'name' => $cat->name, 'slug' => $cat->slug );
}
?>
<?php foreach($cats as $k => $v) : ?>
<?php echo $cats[$k]['name']; ?>
<?php endforeach; ?>
</p>
<p class="tags">
<strong>Tags: </strong>
<?php $tags = wp_get_post_tags($post->ID); ?>
<?php foreach ($tags as $tag) : ?>
<?php echo $tag->name; ?>
<?php endforeach; ?>
</p>
</section>
<?php endwhile; endif; ?>
<?php get_sidebar('news'); ?>
</section>
<section class="middle">
</section>
</article>
So page-news.php are where my news article reside, and the user can get the category using the link generated by <?php echo $cats[$k]['name']; ?>
I don't think you're outputting anything in category.php based on the code above. the_post() doesn't echo anything. It just puts the next record into $post. Try this...
<?php
get_header();
$cat = get_category(get_query_var("cat"));
var_dump($cat); //make sure that there really is a valid category and it's the right one
?>
<h1 class="page-title"><?php echo $cat->name?></h1>
<?php
if (have_posts()) {
while (have_posts()){
the_post();
<h2><?php the_title()?></h2>
<?php the_content()?>
<?php
}
} else {
?>
<p>No posts found!</p>
<?php
}
?>
<?php
get_footer();
?>
In page-news.php you should probably consider using the_category() to echo out the category links rather than constructing the links yourself -- that way you'll know that the links are valid....
<p class="tags"><?php the_category()?></p>
You can use this function inside your page template to loop the posts