Magento 1.7.0.0 FishPig - Excluding Category - php

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
}
?>

Related

How to edit this table data to become a link

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>

How to display top sellers by date range in Magento

Is there anyway to display best sellers by date range? In example 30 days, 60 days, etc
This is my current bestsellers.phtml and we have no idea what range this data is pulling from
<?php
$params = $this->getData();
if(array_key_exists('limit', $params)) {
$limit = $this->getData('limit');
} else {
$limit = 3;
}
$products = $this->getBestSellers($limit);
?>
<script type="text/javascript" src="<?php echo $this->getSkinUrl('js/overlay_jquery.js');?>"></script>
<script type="text/javascript" src="<?php echo $this->getSkinUrl('msslider/slider2/stepcarousel.js') ?>"></script>
<script type="text/javascript">
stepcarousel.setup({
galleryid: 'mygallery', //id of carousel DIV
beltclass: 'belt', //class of inner "belt" DIV containing all the panel DIVs
panelclass: 'panel', //class of panel DIVs each holding content
autostep: {enable:false, moveby:1, pause:2000},
panelbehavior: {speed:500, wraparound:true, wrapbehavior:'slide', persist:true},
defaultbuttons: {enable: false, moveby: 1, leftnav: ['<?php echo $this->getSkinUrl('msslider/slider2/arrowl.png')?>', -15, 100], rightnav: ['<?php echo $this->getSkinUrl('msslider/slider2/arrowr.png')?>', -25, 100]},
contenttype: ['inline'] //content setting ['inline'] or ['ajax', 'path_to_external_file']
})
</script>
<div class="category-products home-page-listing">
<div id="mygallery" class="stepcarousel">
<div class="belt products-grid">
<?php if(is_array($products) && count($products)): ?>
<?php $i = 0; foreach($products as $product): ?>
<div class="panel">
<div class="product-topbg">
<div class="product-bottombg">
<div class="product-midbg">
<h2 class="product-name" style="margin: 5px 0px 15px;">
<?php echo $product['category_name']; ?>
</h2>
<div class="overlay"
id="overlay-<?php echo $i; ?>"
>
<a href="<?php echo $product['url']; ?>"
title="<?php echo $product['name']; ?>"
>
<img src="<?php echo $product['image_url']; ?>"
width="160" height="160"
alt="<?php echo $product['name']; ?>"
/>
</a>
</div>
<h2 class="product-name" style="margin: 15px 0px 5px;">
<a href="<?php echo $product['url']; ?>"
title="<?php echo $product['name']; ?>">
<?php echo $product['name']; ?>
</a>
</h2>
<div class="overlay-show"
id="overlay-show-<?php echo $i;?>"
>
<div class="product-price">
<?php echo $product['price']; ?>
</div>
<div class="price-bottombg"></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var $i = jQuery.noConflict();
$i("#overlay-<?php echo $i;?>").hover(function () {
if ($i("#overlay-show-<?php echo $i;?>").is(":hidden")) {
$i("#overlay-show-<?php echo $i;?>").slideDown("fast");
} else {
$i("#overlay-show-<?php echo $i;?>").slideUp("fast");
}
});
</script>
</div>
<?php $i++; endforeach;?>
<?php endif; ?>
</div>
</div>
<script type="text/javascript">
decorateGeneric($$('ul.products-grid'), ['odd', 'even', 'first', 'last']);
</script>
</div>
Thank you for any help with this code.
As I can see, this is the block that belongs to some 3-d party extension (or smb might have written it). That's why you should locate the block and correct the collection of products it receives via the getBestSellers method.
If you want to see only the last 3 updated products, the easiest way is to add 'order DESC' by 'updated_at' to the collection
Thus, the first 3 products will be the last updated on the list. It will look like that:
$collection->setOrder('update_at', Varien_Data_Collection_Db::SORT_ORDER_DESC);
If you want to get populated some other field, that is different from the 'updated_at', just use its name instead of 'updated_at'.
Note, that you should implement all the changes before the collection gets downloaded.
The block can be find via 'updated_at' or by means of the layout. Additionally, you can search for updated_at inside of the template. Use the most convenient for you method.

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 static block for category showing the subcategories with thumbnails

I'm creating a static block to show the subcategories of a category in Magento. The code is made by me and with some ideas taken in the web.
The idea is to show a title with plain background called back.png as thumbnail of the subcategory when this one hasn't a thumbnail or the category thumbnail if the image is uploaded. For the moment I can't show the thumbnails, could anybody help me?
Thanks.
<div class="product_list" style="width:900px;">
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if($currentCategory->children_count > 0) { ?>
<?php
$cat = Mage::getModel('catalog/category')->load($currentCategory->entity_id);
$_categories = $cat->getChildrenCategories();
?>
<?php if (count($_categories) > 0): ?>
<ul>
<?php foreach($_categories as $_category): //print_r($_category); ?>
<?php
$imageUrl = Mage::getModel('catalog/category')->load($_category->getId())->getThumbnailUrl();
$imageName = substr(strrchr($imageUrl,"/"),1);
$imagePrefx = Mage::getBaseUrl('media')."catalog/category/";
$newImageUrl2 = $imagePrefx.$imageName;
?><div clas="subcat-el">
<li style="float:left; margin-right:10px;">
<div class="subcat-name" style="z-index:20; width:270px; position:absolute; margin-top:134px;text-align: center;">
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>" style="text-decoration:none;">
<h3 style="margin-left:18px; font-family:Helvetica; font-weight:200;text-shadow: 1px 1px 1px #030;font-size: 24px;color:#fff; ">
<?php echo $_category->getName() ?>
</h3>
</a>
</div>
<div style="width:270px; height:270px;background: #fff;
border: 9px solid #fff; border-radius: 3px;-webkit-border-radius: 3px;-moz-border-radius: 3px;-webkit-box-shadow: 0 0 6px 0 rgba(0,0,0,0.15);-moz-box-shadow: 0 0 6px 0 rgba(0,0,0,0.15);box-shadow: 0 0 6px 0 rgba(0,0,0,0.15);margin-bottom:10px;">
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<img src="<?php
if ($newImageUrl2 == $imagePrefx): $newImageUrl2 = Mage::getBaseUrl('skin')."/subcat/back.png";
endif;
echo $newImageUrl2; ?>" alt="<?php echo $_category->getName() ?>" style="width:100%;">
</a>
</div>
</li>
</div>
<?php endforeach; ?>
</ul>
<br style="clear:left;" />
<?php endif; ?>
<?php } else { echo "<h3>No Sub-category found</h3>"; } ?>
</div>
There is no such method by default as in your line:
Mage::getModel('catalog/category')->load($_category->getId())->getThumbnailUrl();
you should try getThumbnail() instead
Or you could try smth like this
$imageUrl = Mage::getBaseUrl('media') . 'catalog/category/' . $_category->getThumbnail()
Or you can try to specify your own method getThumbnailUrl in your own extension
public function getThumbnailUrl(Mage_Catalog_Model_Category $category)
{
return (bool)$category->getThumbnail()
? Mage::getBaseUrl('media') . 'catalog/category/' . $category->getThumbnail()
: '';
}

Dynamic slider using PHP/MySQL &

I have box for dynamic images and desc slider using nivoslider. Now I have big problem -> my PHP code is:
<div id="slider" class="nivoSlider">
<?php
$featured = mysql_query("SELECT * FROM featured WHERE order > 0 ORDER BY order ASC");
$count_featured = mysql_num_rows($featured);
if ($count_featured < 1) { echo "error data" }
while ($swcms = mysql_fetch_assoc($featured)) { ?>
<img width="500" height="170" src="<?php echo "$swcms[image]"; ?>" title="#<?PHP echo "$swcms[id]"; ?>" alt="" border="" />
<div id="<?PHP echo "$swcms[id]"; ?>" class="nivo-html-caption"><?PHP echo "$swcms[desc]"; ?> </div>
<?php $c++; }?>
</div>
This Worked 100% But in firebug I see many GET undefined request after each slide:
I found the problem; nivoslider worked with this method for show images/desc (caption):
<div id="slider" class="nivoSlider">
<img src="..." title="#id" />
</div>
<div id="id" class="nivo-html-caption"></div>
And my PHP loop is:
<div id="slider" class="nivoSlider">
<img src="..." title="#id" />
<div id="id" class="nivo-html-caption"></div>
</div>
How do I fix this PHP code for nivoslider loop?
<div id="slider" class="nivoSlider">
<?php
$featured = mysql_query("SELECT * FROM featured WHERE order > 0 ORDER BY order ASC");
$count_featured = mysql_num_rows($featured);
$captions = '';
if ($count_featured < 1) { echo "error data" }
while ($swcms = mysql_fetch_assoc($featured)) { ?>
<img width="500" height="170" src="<?php echo "$swcms[image]"; ?>" title="#<?PHP echo "$swcms[id]"; ?>" alt="" border="" />
<?php $captions .= '<div id="' . $swcms[id] .'" class="nivo-html-caption"' . $swcms[desc] .'</div>'; ?>
<?php $c++; }?>
</div>
<?php echo $captions; ?>

Categories