Add hreflang to magento language switcher - php

I am trying to add hreflang="ca-fr" or "ca-en" my code is below
<?php if ($_lang->getId() != $this->getCurrentStoreId()): ?>
<li class="language-<?php echo $this->htmlEscape($_lang->getCode()); ?>">
<a href="#" onclick="changeLang('<?php echo $_lang->getCurrentUrl() ?>')"
hreflang="<?php echo $this->htmlEscape($_lang->getCode()); ?>"
id="link-<?php echo $_lang->getId() ?>"><?php echo $frontendNameAssign[$_lang->getId()]; ?></a>
</li>
<?php endif; ?>
I added the 4th line to the file but this displays as "ca_us_english", is there a way to amend this?
I have also tried amending Miscellaneous Scripts with no joy, any help would be grateful.
thanks
Mel

Well in this case you are "right" and Magento is "wrong".
What Magento is actually presenting you as $_lang is not really the lang, but one of your store.
So ca_us_english is the code of your english candian store in your backend (you can have a look at it in the admin under System > Manage Stores)
To get the actual local set for this store you have to use this line of code :
Mage::getStoreConfig('general/locale/code', $_lang->getId())

Related

?php the_permalink() returns wrong post ID and 404 error

I'm having an issue with grabbing the correct post ID using the_permalink() -- see code below:
<?php
while( $wpr->have_posts() ) :
$wpr->the_post();
?>
<?php $wpcover = get_field('whitepaper_cover'); ?>
<li>
<img src="<?php echo $wpcover['url']; ?>" alt="<?php echo $wpcover['alt']; ?>" />
<?php the_title(); ?>
Get it Now
</li>
<?php
endwhile;
wp_reset_postdata();
?>`
For example, on one page the_permalink() is grabbing the post ID link as p=17005 (a post that doesn't exist) when it SHOULD be p=28649, leading to a 404 error. Any ideas?
I tried resetting permalinks and updating elementor plugins, neither of which worked. Also tried various suggetions from browsing stackexchange but none really matched this exact issue. The code looks good to me, but maybe I'm missing something?

PHP wordpress if a text value is empty, echo

I'm building a wordpress theme. In the backend, the user has the option to enter the url for their social networks (i.e. twitter, facebook, instagram etc). These URL's are then dynamically added to images in the theme front end linking to the respective networks.
The issue I have is that if a user doesn't enter a url for a network, I don't want the image to display. I am trying to write code that says, if the url is blank, echo 'class="hidden"' - this class has display:none in the css.
here is a snippet of my php:
<ul class="icons">
<li <?php if (get_theme_mod('footer_twitter')==0) {echo 'class="hidden"'; } ?>><span class="label">Twitter</span></li>
</ul>
and the css:
ul.icons li.hidden {
display:none;
}
The php code above currently outputs the echo statement for all cases, even when a url is entered in the backend. Can anyone help me with this code
Check the return of "get_theme_mod()" You can check this by using, cause i dont think it "== 0". http://codex.wordpress.org/Function_Reference/get_theme_mod
var_dump(get_theme_mod('footer_twitter'));
//string(0)
Here is your new code:
<ul class="icons">
<li class="<?php echo empty(get_theme_mod('footer_twitter')) ? 'hidden' : ''; ?>">
<a href="<?php echo get_theme_mod('footer_twitter'); ?> " class="icon circle fa-twitter">
<span class="label">Twitter</span>
</a>
</li>
</ul>
Please check this Syntax: http://php.net/manual/en/control-structures.alternative-syntax.php its the best way to code control structures in your "View" code.
<?php if (!empty (get_theme_mod( 'set_address2' ))) {
echo get_theme_mod( 'set_address2');
}?>
This seemed to work for me in Wordpress.
Let me know if this works.

add product link to sku (or product name) in new order mail

hy,
i'm trying to add a link to the new order email that the customer is getting when he is placeing a new order in magento (my version 1.6.2.0 )
i have edited /public_html/app/design/frontend/base/default/template/email/order/items/order/default.phtml
with the following:
<?php $_item = $this->getItem() ?>
<?php $_order = $this->getItem()->getOrder() ?>
----
<!-- Start of edit file -->
<a href="<?php echo $this->getProductUrl($_item) ?>">
<?php echo $this->htmlEscape($this->getSku($_item)) ?></a>
When i receive the confirmation email in the sku column the color changes form black ( default css ) to light blue link like, but it does not have any link property as shown below:
email_photo
I have also tried :
<a href="<?php echo $this->getUrlPath($_item) ?>">
<?php echo $this->htmlEscape($this->getSku($_item)) ?></a>
and i end up with the same thing.
Can anyone tell me what i'm doing wrong ?
Thanks.
In line
<a href="<?php echo $this->getUrlPath($_item) ?>">
$this is an instance of block *Mage_Sales_Block_Order_Email_Items_Order_Default*. It does not have a function getUrlPath() or getProductUrl.
You should use your $_item variable to get a product object and then it to get its URL
$_item->getProduct()->getProductUrl()
I earlier tried this code:
<?php echo $this->htmlEscape($this->getSku($_item)) ?>
Magento 2
To link a product name with its product page in your order emails, edit following files:
Magento_Sales/templates/email/items/order/default.phtml
Magento_Sales/templates/email/items/invoice/default.phtml
Magento_Sales/templates/email/items/shipment/default.phtml
To get the product URL, use the following snippet of code and insert it into a href attribute of the link.
<?= $_item->getProduct()->getProductUrl(); ?>
For example,
<p class="product-name"> <?= $block->escapeHtml($_item->getName()); ?> </p>
The result of the snippet of code will be a clickable product name in Magento Emails.
Tutorial from: https://themes.email/magento/product-links-in-magento-order-emails.html

Using php to add classes to looped data in WP e-commerce

In WP e-commerce, I have the following in my products page template:
<ul id="product-categories">
<?php $counter = 1; ?>
<?php wpsc_start_category_query(array('category_group'=>get_option('wpsc_default_category'), 'show_thumbnails'=> get_option('show_category_thumbnails'))); ?>
<li class="four columns<?php if ($counter % 4 == 1){echo ' alpha';}else if ($counter % 4 == 0){echo ' omega';} ?>">
<?php $counter++ ; ?>
<a title="<?php wpsc_print_category_name(); ?>" href="<?php wpsc_print_category_url();?>">
<?php wpsc_print_category_image('auto', 'auto'); ?>
<span><?php wpsc_print_category_name(); ?></span>
</a>
</li>
<p><?php echo $counter ?></p>
<?php wpsc_end_category_query(); ?>
</ul>
As you can see, for every 4n-3th item, I am trying to add an alpha class, and to every 4nth item, I am trying to add an omega class to my list items, such that the display works with a grid framework.
My issue is, start_wpsc_category_query does not appear to be 'looping' like a standard WP loop, as my echoed counter value remains at 2 for every item, hence no class is added.
Does anyone know how to fix this code to make the counter value increase each time, or have a better (PHP) way of addressing the problem if you've dealt with WP e-commerce before?
Another way of approaching would be to write a foreach loop for WP e-commerce categories, if anyone knows how to do this.
Thanks a million in advance.

How to Show Accurate Category Post Count?

I've got some code in my blog sidebar that is designed to show the number of posts in a particular category. It works, kind of. It will only show up to the number 5 and then it stops updating the post count. Any ideas on how to fix?
Here's the code for one of the categories:
<?php
$count_posts = get_posts('post_type=post&category_name=Software')
?>
<li id="nav1">
<a class="<?php if ($current_cat == get_cat_ID('Software')) echo "software-active active"; ?>" href="<?php echo get_category_link(get_cat_ID('Software')) ?>" title="Software">Software (<?php echo count($count_posts) ?>)</a>
Here's a link to the blog. thanks for your help!
Change:
get_posts('post_type=post&category_name=Software')
To:
get_posts('post_type=post&category_name=Software&numberposts=-1');

Categories