Skip to content

Instantly share code, notes, and snippets.

@xlawok
xlawok / functions.php
Created September 5, 2022 13:03
navxt breadcrumbs
function add_link_to_breadcrumbs( $breadcrumb_obj ) {
if(is_page(1044)||is_page(532)||is_page(542)||is_page(553)||is_page(555)||is_page(558)||is_page(1046)){
$first_item = new bcn_breadcrumb();
$first_item->set_title('Produkty');
$first_item->set_url(get_permalink(7));
// Add as second item in list.
$a_leng=count($trail->breadcrumbs);
array_splice( $breadcrumb_obj->breadcrumbs, $a_leng-1, 0, array( $first_item ) );
}
@xlawok
xlawok / products.tpl
Created June 1, 2022 07:59
Presta - pagination loaded with ajax - add page number to title and h1
<script type="text/javascript">
{literal}
window.setTimeout(function(){
// on click refresh variables
if (document.documentElement.lang == "pl"&&(window.location.hostname).includes("amberdream")){
var awgetpageno = (new URLSearchParams(window.location.search.slice(1))).get('page');
var content = " - strona "+awgetpageno;
var theh1=document.querySelector('#category .box-breadcrumb h1.category-name');
var thetitle=document.title;
// replace old " - strona XX" string with new
@xlawok
xlawok / product-list.tpl
Created June 1, 2022 07:59
Presta - pagination with ajax load - add pagination No to title and h1
<script type="text/javascript">
{literal}
window.setTimeout(function(){
// on click refresh variables
var awgeturl=window.location.href;
var awgeturl= awgeturl.split('#/page-')[1];
var content = " - strona "+awgeturl;
var theh1=document.querySelector('#category h1.aw-category');
var thetitle=document.title;
// replace old " - strona XX" string with new
@xlawok
xlawok / head.tpl
Created June 1, 2022 07:51
Prestashop - add pagination to meta title
{if $smarty.server.HTTP_HOST=='amberdream.pl'&&$language.iso_code=='pl'}
{if $page.page_name=="index"}
<title>{block name='head_seo_title'}Sklep internetowy z produktami z bursztynu - Amber Dream{/block}</title>
{else}
<title>{block name='head_seo_title'}{$page.meta.title} {if isset($listing.pagination)&&$listing.pagination.current_page > 1} - Strona - {$listing.pagination.current_page} {/if} - Amber Dream{/block}</title>
{/if}
{else}
<title>{block name='head_seo_title'}{$page.meta.title} {/block}</title>
{/if}
@xlawok
xlawok / functions.php
Created April 29, 2022 08:20
navxt breadcrumbs - remove item from breadcrumbs
<?php
add_action('bcn_after_fill', 'pp_navxt_modify_breadcrumbs');
function pp_navxt_modify_breadcrumbs($trail)
{
if(is_tax('kategoria')||is_singular ('produkt' ) )
{
// reverse order of array of breadcrumbs so if I want to remove second item it will be one before last so
// count array and minus 2
$a_leng=count($trail->breadcrumbs);
array_splice($trail->breadcrumbs,$a_leng-2,1);
@xlawok
xlawok / head.tpl
Created April 12, 2022 13:08
PRestashop current page number
{if isset($listing.pagination)}
{$listing.pagination.current_page}
{/if}
@xlawok
xlawok / slide.js
Created March 3, 2022 09:47
Vanilla JS slider with touch feature, counting slides
window.addEventListener('load', function () {
var offer_wrapper= document.querySelector('.aw-front-page-offer .slider-wrapper');
var offer_slides=offer_wrapper.querySelectorAll('.offer-slide');
var offer_s_prev = document.querySelector('.aw-front-page-offer .prev');
var offer_s_next = document.querySelector('.aw-front-page-offer .next');
if (typeof(offer_slides) != 'undefined' && offer_slides != null){
var slides_count=offer_slides.length;
var times_to_left=0;
var move_me= 0;
if(slides_count > 1){
@xlawok
xlawok / head.tpl
Created October 26, 2021 11:46
PRESTASHOP self canonical for category pagination and next/prev
{if isset($smarty.get.id_category) }
<link rel="canonical" href="{$page.canonical}">
{if isset($listing.pagination)}
{foreach from=$listing.pagination.pages item="page"}
{if $page.type === 'previous'}
<link rel="prev" href="{$page.url}">
{elseif $page.type === 'next'}
<link rel="next" href="{$page.url}">
@xlawok
xlawok / head.tpl
Created September 20, 2021 08:24
Prestashop custom canonicals for specific categories or products
{if isset($smarty.get.id_category) }
{if $smarty.get.id_category=='275'}
<link rel="canonical" href="{$link->getCategoryLink(269)}">
{elseif $smarty.get.id_category=='280'}
<link rel="canonical" href="{$link->getCategoryLink(270)}">
{elseif $smarty.get.id_category=='14'}
<link rel="canonical" href="{$link->getCategoryLink(13)}">
{elseif $smarty.get.id_category=='43'}
<link rel="canonical" href="{$link->getCategoryLink(42)}">
@xlawok
xlawok / img-lazy-load.js
Created September 16, 2021 07:01
images lazy load
(function ($) {
var lazy_images_elements = [].slice.call(document.querySelectorAll("[data-lazy-src]"));
if ("IntersectionObserver" in window) {
var lazy_src_observer = new IntersectionObserver(function (entries, observer) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
var $lazy = $(entry.target);
$lazy.attr("src", $lazy.attr("data-lazy-src"))