How to show specific attribute under product name on Woocommerce Shop Page - html

I've been struggling to find information about how to achieve this:
I want for one specific attribute (Brand), to be visible and present under the product name on the Shop Page.
How can I achieve this?
Theme: Zakra
Thanks in advance.
Alex.

Use the below code display the attribute below the product title on the shop page.
I guess the taxonomy name for the brand should be (pa_brand). If the name is different then replace the taxonomy name of BRAND and replace(pa_brand) it in the below code.
add_action( 'woocommerce_after_shop_loop_item_title', 'display_brand_attribute', 5 );
function display_brand_attribute() {
global $product;
$taxonomy = 'pa_brand';
echo '<span class="attribute-brand">' . $product->get_attribute($taxonomy) . '</span>';
}

Related

How to add pagination for wishlist products in magento 1.9

I am trying to get products on the page-wise for wishlist collection. I was getting a count for product collections in the below code. I have set the page size to one but it's showing the product count two. Please help me to fix this. Thanks.
$wishlist1 = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer, true)
->setCurPage($page_num)
->setPageSize(1)
->load();
foreach($wishlist1->getItemCollection() as $product){
$_product = Mage::getModel('catalog/product')->load($product['product_id']);//product id here
echo $product['product_id'];
}
Please try with this code:
<?php
$customer = Mage::getModel("customer/customer")->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->loadByEmail('mohit#streammarket.co.uk');
$wishlistItems = Mage::getModel('wishlist/item')->getCollection()
->setWebsiteId($customer->getWebsiteId())
->setCustomerGroupId($customer->getGroupId())
->setCurPage(1)
->setPageSize(1)
->load();
?>

show subcategories of parent category when no subcategories in category page

In magento when we click on a category it takes us to category page and shows
(if exists) subcategories of the clicked category in layered navigation on left.But when we click on a category that has no subcategories it show empty on that category page in layered navigation on left. What I want is to show subcategories of the parent if the current category has no subcategories.For this I have done the following but did not work for me.
I have tried to add the following to to
app/code/core/Mage/Catalog/Model/Layer/Filter/Category.php
if(count($categoty->getChildrenCategories())){
$categories = $categoty->getChildrenCategories();
}else{
$categories = $categoty->getParentCategory()->getChildrenCategories();
}
and removed line #163
$categories = $categoty->getChildrenCategories();
Please suggest me a solution. Any help will be greatly appreciated.
I have found the solution. I have to put the above login in left.phtml
app/design/frontend/theme/template/catalog/navigation/left.phtml
$categoty = Mage::registry('current_category');
$categories = $category->getChildrenCategories();
//$_categories = $this->getCurrentChildCategories();
if(count($categoty->getChildrenCategories())){
$_categories = $categoty->getChildrenCategories();
}else{
$_categories = $categoty->getParentCategory()->getChildrenCategories();
}
and it worked like a charm! Hope it will help someone else!

MediaWiki: changing the label of a category at the bottom of the page

In mediawiki, is it possible to change the label of a 'Category' at the bottom of an article.
For example for the following article:
=Paris=
blablablablablabla
[[Category:place_id]]
I'd like to see something more verbose like (the example below doesn't work):
=Paris=
blablablablablabla
[[Category:place_id|France]]
Note: I don't want to use a 'redirect' and I want to keep my strange ids because they are linked to an external database.
I do not think mediawiki is supporting this feature.
However, how about using:
[[Category:France]]
in your page, and set it into the category named with your id? France would just be a subcategory of "place_id", and you could use more terms all linked to the parent category. For this, you just need to edit the category page for "France", inserting:
[[Category:place_id]]
An alternative would be to put your page in both categories, but in this case, the id would still be displayed:
[[Category:place_id]]
[[Category:France]]
You could do this with an OutputPageMakeCategoryLinks hook. Alas, the interface for that hook seems to be a bit inconvenient — as far as I can tell, it's pretty much only good for replacing the standard category link generation code entirely. Still, you could do that is you want:
function myOutputPageMakeCategoryLinks( &$out, $categories, &$links ) {
foreach ( $categories as $category => $type ) {
$title = Title::makeTitleSafe( NS_CATEGORY, $category );
$text = $title->getText();
if ( $text == 'Place id' ) {
// set $text to something else
}
$links[$type][] = Linker::link( $title, htmlspecialchars( $text ) );
}
return false; // skip default link generation
}
$wgHooks['OutputPageMakeCategoryLinks'][] = 'myOutputPageMakeCategoryLinks';
(The code above is based on the default category link generation code in OutputPage.php, somewhat simplified; I assume you're not using language variant conversion on your wiki, so I removed the parts that deal with that. Note that this code is untested! Use at your own risk.)

MySQL question: Appending text to a wordpress post, but only if it's in a certain category

I need to amend (via CONCAT, presumably) something to every wordpress post if it belongs to a certain category (say, category ID 7), but I'm struggling to get it to work.
To test, I'm first trying to select all the relevant posts. So far, I have the following:
SELECT post_title
FROM cruise_wp_posts
LEFT JOIN cruise_wp_term_relationships
ON cruise_wp_term_relationships.object_id = cruise_wp_posts.ID
WHERE term_taxonomy_id = 87;
However, it only lists posts that are only in category 87 - I need all posts that are in category 87 (and possibly other categories too)
I'm a MySQL newbie, and this is really breaking my brain.
Any pointers would be passionately welcomed.
The best way to do it is to filter it in as needed. This way the addition is made everywhere the_content is used and not just in the templates you modify.
<?php
function my_content_concat($the_content) {
if (in_category(7)) {
$the_content .= '<br /><br />foo!';
}
return $the_content;
}
add_filter('the_content', 'my_content_concat', 9);
?>
in_category can take the id, name or slug of your target category.
I put the filter at 9 so that it runs before WordPress texturizes the content. If you don't need that run it at 11.
Why not just use get_the_category( $id ) and ammend the text when you output the post?
$cat = get_the_category( $postID );
if ($cat == 7) {
//Add text here
}

html listbox to show additonal txt in extra field outside of listbox

I have the following db-retrieve which results in the Listbox I like to have.
But I need $desc2 to be shown under the listbox in a separate field and it must change its content when the user clicks on an other item in the list:
Here is the retrieve which works:
echo "<form action=\"admin.php\" method=\"post\">";
echo "Industry:<SELECT name=\"industry\" size=\"10\">";
$result=sql_query("SELECT cat, title, desc, parentid
FROM industries
WHERE language='english'");
while(list($cid2, $ctitle2, $desc2, $parentid2) = sql_fetch_row($result)) {
if ($cid2==$userindustry) {
$sel = "selected";
} else {
$sel = "";
}
if ($parentid2!=0) $ctitle2=getparentindustry($parentid2,$ctitle2);
echo "<option value=\"$cid2\" $sel>$ctitle2</option>";
}
echo "</SELECT>
<br>$desc2<br> # place to show description of list item
<input type=\"hidden\" name=\"op\" value=\"save\">
<input type=\"submit\" value=\"Go\"></form><br>";
As I'm now searchin for some time, but didn't found something, hopefully someone here could help me.
The code for the side is in php.
Thanks in advance.
You would have to store $desc2 to a temporary variable in the loop, and use the temporary variable after the select to show the temporary variable.
I would however, point out that in general, this is probably the wrong way of going about this code, and that your problem is deeper in your implementation :)