How to edit this table data to become a link - php

i am using a table on my website for products.
At the moment only the image is clickable but i want the whole line or at least all the information in the table to be linking to the productpage.
The image has this and works as a link to the productpage:
<td style="width: 15%;">
<div style="padding: 15px;">
<a href="<?php the_permalink() ?>" target="_blank" class="thumbnail alignleft"><img src="<?php
if (has_post_thumbnail($post->ID))
{
$img_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'single-post-thumbnail');
echo woof_aq_resize($img_src[0], get_tpl_option('tpl_3_img_width', $options), get_tpl_option('tpl_3_img_height', $options), true);
} else
{
echo WOOF_LINK . 'img/not-found.jpg';
}
?>" alt="<?php the_title() ?>" /></a>
</div>
<div style="clear: both;"></div>
</td>
Now i am trying to do the same thing for all the other info in the table wich have code like this:
<td style="width: auto;"><?php
$product = new WC_Product(get_the_ID());
echo $product->get_attribute('pa_voedings-spanning-dcac');
?>
</td>
Or even better make the whole line of the table a link. Thank you for your time,
Sjoerd

You can simply wrapp each cell content with a "a" balise like this:
<td style="width: auto;">
<?php $product = new WC_Product(get_the_ID()); ?>
<a href="<?php the_permalink() ?>" target="_blank">
<?php echo $product->get_attribute('pa_voedings-spanning-dcac'); ?>
</a>
</td>

Related

Retrieving many images from mysql automatically by an echo and enlarging them on click

I have a PhP shopping cart for autoparts and I need to be able to enlarge the retrieved image upon clicking on it. The problem is I can't manually assign an ID to every picture because I'm echoing them from the database.
I've tried assigning one ID/class to all the pictures that get retrieved and enlarge them on click using the JS function but can't get it working.
$items_array = $db_controller->runQuery("SELECT * FROM mystuff ORDER BY ID ASC");
if (!empty($items_array)) {
foreach($items_array as $key=>$value){
?>
<div class="DisplayCartItems">
<form method="post" action="?action=add&mscode=<?php echo $product_array[$key]["mscode"]; ?>">
<img src="<?php echo $product_array[$key]["msimage"]; ?>" class="imgcartdisplay" align="alignnone"/> /* Right here I need some help */
<div class="lif"><strong>Category:</strong> <?php echo $product_array[$key]["mscategory"]; ?></div>
<div class="lif"><strong>Category №:</strong> <?php echo $product_array[$key]["mscatnum"]; ?></div>
<div class="lif"><strong>Stock №:</strong> <?php echo $product_array[$key]["msnomer"]; ?></div>
<div class="lif"><strong>Mark:</strong> <?php echo $product_array[$key]["msmark"]; ?></div>
<div class="lif"><strong>Model:</strong> <?php echo $product_array[$key]["msmodel"]; ?></div>
<div class="lif"><strong>Year:</strong> <?php echo $product_array[$key]["msyear"]; ?></div>
<div class="lif"><strong>Price:</strong> <?php echo "$".$product_array[$key]["msprice"]; ?></div>
<div style="text-align:center"><input type="number" name="oap" placeholder="Offer a price:"></div>
<br class="">
<div class="cartan">
Quantity: <input type="text" class="product-quantity" name="quantity" value="1" size="2" />
<br class="">
<input type="submit" onclick="AddCartAlert()" value="Add to cart" /></div>
</form>
</div>
<?php
}
}
?>```
I think if I can somehow assign an ID or class name for every picture that get displayed from the MySql and onclick change it's width/height, that'd do the job.
If I have correctly understood:
you should replace this:
<img src="<?php echo $product_array[$key]["msimage"]; ?>" class="imgcartdisplay" align="alignnone"/> /* Right here I need some help */
with:
<a target="_blank" href="<?php echo $product_array[$key]["msimage"]; ?>"><img src="<?php echo $product_array[$key]["msimage"]; ?>" class="imgcartdisplay" align="alignnone"/></a>
for opening the image in another tab.
Or... if you mean something like this https://lokeshdhakar.com/projects/lightbox2/#examples you have to use javascript (for example: Image #1)
In your case something like this: (of course you need to add lightbox script: https://lokeshdhakar.com/projects/lightbox2/#getting-started)
<a data-lightbox="image-1" data-title="My caption" href="<?php echo $product_array[$key]["msimage"]; ?>"><img src="<?php echo $product_array[$key]["msimage"]; ?>" class="imgcartdisplay" align="alignnone"/></a>

Display tick image when click color for a particular id

I want to display tick image when click one color which is a background color.
My phtml coding is
<?php foreach($this->getSolidColors() as $key => $_solidColors) : ?>
<li id="font-colr-<?php echo $_solidColors['id'] ?>" onclick="selectcolor("<?php echo $_solidColors['id'] ?>");" data-id="<?php echo $_solidColors['id'] ?>" data-img="<?php echo $this->getSkinUrl('css/images/checked.png'); ?>" class="cursor font-color" style="background: #<?php echo $_solidColors['hexa'] ?>" data-color="#<?php echo $_solidColors['hexa'] ?>">
<span class="sprite"></span>
<img id="tick" src="<?php echo $this->getSkinUrl('css/images/checked.png'); ?>" width="80%" height="80%" style="display:none; padding-left:10px;">
</li>
<?php endforeach; ?>
function selectcolor() {
var id = jQuery('#font-colr').attr('data-id');
jQuery('#tick').css('display', 'block');
}
When I click particular color the tick image is displayed for the first color only but I want to get image for which color I clicked and if I select another color the previous tick mark should be disappeared.
The issue you have is that the id of 'tick' is repeated throughout your page, which is invalid as id must be unique. You should change that to a common class instead.
You should also use unobtrusive JS to attach your event handlers instead of the outdated on* event attributes. Try this:
<?php foreach($this->getSolidColors() as $key => $_solidColors) : ?>
<li class="cursor font-color" id="font-colr-<?php echo $_solidColors['id'] ?>" data-id="<?php echo $_solidColors['id'] ?>" data-img="<?php echo $this->getSkinUrl('css/images/checked.png'); ?>" style="background: #<?php echo $_solidColors['hexa'] ?>" data-color="#<?php echo $_solidColors['hexa'] ?>">
<span class="sprite"></span>
<img class="tick" src="<?php echo $this->getSkinUrl('css/images/checked.png'); ?>">
</li>
<?php endforeach; ?>
.tick {
width: 80%;
height: 80%
display: none;
padding-left: 10px;
}
$('li.font-color').click(function() {
var id = $(this).data('id'); // I presume you use this value somewhere in your code?
$(this).find('.tick').show();
});
IDs must be unique. In your loop, add a unique id for each tick:
<li id="font-colr-<?php echo $_solidColors['id'] ?>" onclick="selectcolor("<?php echo $_solidColors['id'] ?>");" data-id="<?php echo $_solidColors['id'] ?>" data-img="<?php echo $this->getSkinUrl('css/images/checked.png'); ?>"
class="cursor font-color"
style="background: #<?php echo $_solidColors['hexa'] ?>"
data-color="#<?php echo $_solidColors['hexa'] ?>">
<span class="sprite"></span>
<img id="tick-<?php echo $_solidColors['id'] ?>" src="<?php echo $this->getSkinUrl('css/images/checked.png'); ?>" width="80%" height="80%" style="display:none; padding-left:10px;">
</li>
and in your selectColor where you pass the id, use it:
function selectcolor(id){
jQuery('#tick-'+id).css('display', 'block');
}

echo active image alt text in <p>

I'm trying to figure out some php code.
I have a slider inside a fancybox popup.
What i need to do is then i click on image it gets me its alt text in "image-product-name" P class.
<div class="modal-body">
<button class="close">×</button>
<div class="UI-IMAGE image">
<img src="<?php echo Mage::helper('core/image')->init($_product, 'image', 'catalog/product')->resize(640, 400) ?>" width="640px" height="400px"
alt="<?php echo $this->htmlEscape($this->getImageLabel()) ?>"
title="<?php echo $this->htmlEscape($this->getImageLabel()) ?>">
</div>
<p class="image-product-name"><?php echo $_product->getName() ?></p>
<?php if (count($this->getGalleryImages()) > 0): ?>
<div class="previews UI-PREVIEWS">
<ul>
<?php foreach ($this->getGalleryImages() as $_image): ?>
<li>
<a href="#"
title="<?php echo $this->htmlEscape($_image->getLabel()) ?>"
data-image="<?php echo $this->helper('core/image')->init($this->getProduct(), 'thumbnail', 'catalog/product', $_image->getFile())->resize(640, 400); ?>">
<img src="<?php echo $this->helper('core/image')->init($this->getProduct(), 'thumbnail', 'catalog/product', $_image->getFile())->resize(78, 78); ?>" width="78px" height="78px"
alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>"/>
</a>
</li>
<?php endforeach ?>
</ul>
</div>
<?php endif ?>
</div>
Right now its just echoes an image name.
What should i change in order to make it echo active image alt text?
You need javascript for this. In the next example I've used jQuery:
$('.imgClass').click(function(){ //When user click on your img
var altImg = $(this).attr('alt'); //Save the alt attribute into a variable
$('p.image-product-name').html(altImg); //Place the variable between the p tags;
});
without js just change the variable from:
<p class="image-product-name"><?php echo $_product->getName() ?></p>
to
<p class="image-product-name"><?php echo $this->htmlEscape($_image->getLabel()) ?></p>
pretty straighforward

Foreach in table...limit to 7 then create new row

I have this code printing the output of a list of best selling products. The problem is it spans horizontally without breaking and goes off the side of the screen after 7 products.
What I'd like to do, and am completely stymied as my attempts have been fruitless, is to have the 8th to 14th entries start a new row. How do I need to modify my code in order to accomplish this?
<?php $products = $this->getCollection(); ?>
<?php if ($products && $products->count() > 0) { ?>
<div class="block block-list block-viewed">
<div class="block-title">
<strong><span><?php echo $this->__($this->getHeader()) ?></span></strong>
</div>
<div class="block-content">
<table class="amsorting-table">
<tr>
<?php foreach ($products as $p) { ?>
<td style="padding: 15px 15px 0px 15px;">
<a href="<?php echo $p->getProductUrl() ?>" title="<?php echo $this->htmlEscape($p->getName()) ?>" class="product-image"><img
src="<?php echo $this->helper('catalog/image')->init($p, 'small_image')->resize(125) ?>" width="125" height="125" alt="<?php echo
$this->htmlEscape($p->getName()) ?>" /></a>
<h3 class="product-name"><a href="<?php echo $p->getProductUrl() ?>" title="<?php echo $this->htmlEscape($p->getName())
?>"><?php echo $this->htmlEscape($p->getName()) ?></a></h3>
<?php echo $this->getPriceHtml($p, true) ?>
</td>
<?php } ?>
</tr>
<tr>
<?php foreach ($products as $p) { ?>
<td style="padding: 0px 15px 15px;">
<?php if($p->isSaleable()): ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart"
onclick="setLocation('<?php echo $this->getAddToCartUrl($p) ?>')"><span><span><?php echo $this->__('Add to Cart')
?></span></span></button>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
<?php } ?>
</td>
</tr>
</table>
</div>
</div>
<?php } ?>
Do your <tr> tag conditionally, based on whether the current product index is divisible by 7
<table class="amsorting-table">
<?php
foreach ($products as $i => $p) {
if ($i % 7 == 0) { // start a new row on product 0, 7, 14, etc
if ($i > 0) { // if this is not the 1st product, close the previous row
?></tr><?php
}
?><tr><?php
}
... your code the display the table cell for the current product
}
// after the loop, we need to close the last row
?></tr><?php
...

Magento 1.7.0.0 FishPig - Excluding Category

EDIT 01-28-13: Revised to clarify my question.
I'm using Magento 1.7.0.0 and FishPig WP full integration. We have successfully listed products from specific category and from all categories but was wondering if we can exclude in some cases from specified category. I found solutions to do this in functions.php within WordPress but this does not seem to work.
Here is the current code that displays posts from all categories. We'd like to add an exception so WordPress 1 Category can be excluded.
Here is the code that displays from all categories which I'd like to NOT include category "Press_HomePage":
$col_posts = Mage::getResourceModel('wordpress/post_collection')->addIsPublishedFilter();
$posttotal = count($col_posts->getAllIds());
$posttotid = $col_posts->getAllIds();
//i<=2 means displays last 2 posts
//display latest 2 posts...
for ( $i=1; $i<=2; $i++ )
{
?>
<div class="blog">
<h2><?php echo $col_posts->getItemById($posttotid[$posttotal-$i])->getPostDate(); ?></h2>
<h1><?php echo $col_posts->getItemById($posttotid[$posttotal-$i])->getPostTitle(); ?></h1>
<div style="float:left; margin-top:15px; margin-bottom:25px;">
<?php
$featured_img = $this->getSkinUrl('images/pree_emty.png');
if($featuredImage = $col_posts->getItemById($posttotid[$posttotal-$i])->getFeaturedImage())
{
$featured_img = $featuredImage->getAvailableImage();
}
?>
<img style="float: left;" src="<?php echo $featured_img; ?>" width="204" height="204" alt="" />
<div style="float: left; width: 580px; padding: 10px;">
<p><?php echo substr(strip_tags($col_posts->getItemById($posttotid[$posttotal-$i])->getPostContent()), 0, 400); ?></p>
<p>
<a href="<?php echo $col_posts->getItemById($posttotid[$posttotal-$i])->getUrl(); ?>">
<img src="<?php echo $this->getSkinUrl('images/view_btn.jpg'); ?>" width="170" height="32" alt="" />
</a>
</p>
</div>
</div>
</div>
<?php
}
?>
Let me know if I need to clarify myself. I appreciate your time.
//loki - get all the post ids
$col_posts = Mage::getResourceModel('wordpress/post_collection')->addIsPublishedFilter();
$posttotid = $col_posts->getAllIds();
//loki - get all the press ids
$col_posts_press = Mage::getResourceModel('wordpress/post_collection')->addIsPublishedFilter()->addCategorySlugFilter('press_homepage');
$posttotid_press = $col_posts_press->getAllIds();
//loki - removing the press_homepage category from array and reindexing
$blogposts = array_diff($posttotid, $posttotid_press);
$blogposts = array_values($blogposts);
$posttotal = count($blogposts);
//i<=2 means displays last 2 posts
//display latest 2 posts...
for ( $i=1; $i<=2; $i++ )
{
?>
<div class="blog">
<h2><?php echo $col_posts->getItemById($blogposts[$posttotal-$i])->getPostDate(); ?></h2>
<h1><?php echo $col_posts->getItemById($blogposts[$posttotal-$i])->getPostTitle(); ?></h1>
<div style="float:left; margin-top:15px; margin-bottom:25px;">
<?php
$featured_img = $this->getSkinUrl('images/pree_emty.png');
if($featuredImage = $col_posts->getItemById($blogposts[$posttotal-$i])->getFeaturedImage())
{
$featured_img = $featuredImage->getAvailableImage();
}
?>
<img style="float: left;" src="<?php echo $featured_img; ?>" width="204" height="204" alt="" />
<div style="float: left; width: 580px; padding: 10px;">
<p><?php echo substr(strip_tags($col_posts->getItemById($blogposts[$posttotal-$i])->getPostContent()), 0, 400); ?></p>
<p>
<a href="<?php echo $col_posts->getItemById($blogposts[$posttotal-$i])->getUrl(); ?>">
<img src="<?php echo $this->getSkinUrl('images/view_btn.jpg'); ?>" width="170" height="32" alt="" />
</a>
</p>
</div>
</div>
</div>
<?php
}
?>

Categories