Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
N
NAP-wordpress
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Marwa Sfari
NAP-wordpress
Commits
540de525
Commit
540de525
authored
Aug 22, 2017
by
Nahla Shiri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
679 filtres contextuel et non global
parent
f0bd5a5b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
105 additions
and
11 deletions
+105
-11
functions.php
wp-content/themes/nap/functions.php
+57
-3
archive-product.php
wp-content/themes/nap/woocommerce/archive-product.php
+48
-8
No files found.
wp-content/themes/nap/functions.php
View file @
540de525
...
@@ -431,7 +431,7 @@ function nap_image_resize($image,$size){
...
@@ -431,7 +431,7 @@ function nap_image_resize($image,$size){
function
nap_get_item
(
$post_ID
,
$args
=
null
,
$current_page
=
''
,
$options
=
null
)
{
function
nap_get_item
(
$post_ID
,
$args
=
null
,
$current_page
=
''
,
$options
=
null
,
$search
=
null
)
{
$link
=
$image
=
$size
=
''
;
$link
=
$image
=
$size
=
''
;
if
(
isset
(
$options
))
{
if
(
isset
(
$options
))
{
if
(
$options
[
'dwnldLink'
])
{
if
(
$options
[
'dwnldLink'
])
{
...
@@ -447,8 +447,38 @@ function nap_get_item($post_ID, $args = null, $current_page = '', $options = nul
...
@@ -447,8 +447,38 @@ function nap_get_item($post_ID, $args = null, $current_page = '', $options = nul
}
}
}
}
if
(
isset
(
$search
[
'pa_couleur'
])
&&
$search
[
'pa_couleur'
]
!=
''
){
$nap_article
=
'<article class = " visible row">
$colors_value
=
get_the_terms
(
$post_ID
,
'pa_couleur'
);
$filter
=
"hidden"
;
if
(
is_array
(
$colors_value
)){
foreach
(
$colors_value
as
$key
=>
$value
)
{
$code
=
nap_color_attribute
(
$value
->
slug
);
if
(
$code
!=
''
&&
stristr
(
$search
[
'pa_couleur'
],
$code
))
{
$filter
=
"selected"
;
}
}
}
}
if
(
isset
(
$search
[
'pa_format'
])
&&
$search
[
'pa_format'
]
!=
''
){
$format_value
=
get_the_terms
(
$post_ID
,
'pa_format'
);
$filter
=
"hidden"
;
if
(
is_array
(
$format_value
)){
foreach
(
$format_value
as
$key
=>
$value
)
{
if
(
stristr
(
$search
[
'pa_format'
],
$value
->
name
))
{
$filter
=
"selected"
;
}
}
}
}
if
(
isset
(
$filter
))
$class
=
$filter
;
$nap_article
=
'<article class = " visible row '
.
$class
.
'">
<a href="#"></a>
<a href="#"></a>
<figure data-bg = "" class = "'
.
$size
.
' transition">
<figure data-bg = "" class = "'
.
$size
.
' transition">
<div class="abs-full article-bg transition"></div>'
;
<div class="abs-full article-bg transition"></div>'
;
...
@@ -611,3 +641,27 @@ function externe_referrer(){
...
@@ -611,3 +641,27 @@ function externe_referrer(){
return
$ref
;
return
$ref
;
}
}
function
nap_attribute_by_category
(
$categorie
,
$attr
){
$args
=
array
(
'post_type'
=>
array
(
'product'
,
'product_variation'
),
'numberposts'
=>
-
1
,
'tax_query'
=>
array
(
array
(
'taxonomy'
=>
'product_cat'
,
'field'
=>
'id'
,
'terms'
=>
$categorie
,
'operator'
=>
'IN'
,
)
)
);
$products
=
get_posts
(
$args
);
$attribute
=
array
();
foreach
(
$products
as
$key
=>
$value
)
{
$attribute
[]
=
array_shift
(
woocommerce_get_product_terms
(
$value
->
ID
,
$attr
,
'names'
));
}
return
array_unique
(
$attribute
);
}
wp-content/themes/nap/woocommerce/archive-product.php
View file @
540de525
<?php
<?php
print_r
(
$_GET
);
/**
/**
* The Template for displaying product archives, including the main shop page which is a post type archive
* The Template for displaying product archives, including the main shop page which is a post type archive
*
*
...
@@ -22,10 +23,32 @@ $current_page = 'catalogue';
...
@@ -22,10 +23,32 @@ $current_page = 'catalogue';
get_header
();
get_header
();
$product
;
$product
;
$cate
=
get_queried_object
();
$cate
=
get_queried_object
();
$cateID
=
$cate
->
term_id
;
print
'******CATID Nahla'
.
$cateID
=
$cate
->
term_id
;
//SubCats
//SubCats
$child_category
=
get_terms
(
'product_cat'
,
array
(
'parent'
=>
$cateID
,
'child_of'
=>
the_category_ID
(),
'exclude'
=>
$cateID
,
'orderby'
=>
'title'
,
'order'
=>
'ASC'
));
$child_category
=
get_terms
(
'product_cat'
,
array
(
'parent'
=>
$cateID
,
'child_of'
=>
the_category_ID
(),
'exclude'
=>
$cateID
,
'orderby'
=>
'title'
,
'order'
=>
'ASC'
));
$products
=
nap_attribute_by_category
(
$cateID
,
'pa_format'
);
print_r
(
$products
);
if
(
is_product_category
()){
global
$product
;
// the array of attributes names
$attribute_names
=
array
(
'pa_format'
,
'pa_matiere'
);
foreach
(
$attribute_names
as
$key
=>
$attribute_name
)
{
// Getting the value of an attribute
$attribute_value
=
array_shift
(
wc_get_product_terms
(
$product
->
id
,
$attribute_name
));
// Displays only if attribute exist for the product
if
(
!
empty
(
$attribute_value
)
||
$attribute_value
==
'0'
){
echo
print
"*********"
.
$attribute_value
;
// Separating each number by a " / "
if
(
$key
<
3
)
echo
' / '
;
}
}
}
?>
?>
<div
class=
"container clearfix"
id=
"catalogue"
data-page =
"
<?php
echo
$cateID
;
?>
"
>
<div
class=
"container clearfix"
id=
"catalogue"
data-page =
"
<?php
echo
$cateID
;
?>
"
>
...
@@ -38,6 +61,7 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
...
@@ -38,6 +61,7 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
</div>
</div>
<div
class=
"right-container"
>
<div
class=
"right-container"
>
<div
class=
"left-panel fixed-full position--after-menu "
>
<div
class=
"left-panel fixed-full position--after-menu "
>
<?php
if
(
$cateID
!=
20
)
:?>
<
div
class
="
filter
-
wrapper
">
<
div
class
="
filter
-
wrapper
">
<div class="
filter
-
btn
fixed
position
--
after
-
menu
">
<div class="
filter
-
btn
fixed
position
--
after
-
menu
">
<div class="
btn
-
container
"><span class="
abs
-
center
font
-
small
">Filtres</span></div>
<div class="
btn
-
container
"><span class="
abs
-
center
font
-
small
">Filtres</span></div>
...
@@ -53,31 +77,46 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
...
@@ -53,31 +77,46 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
$attributes
= array('Univers' => 'pa_univers', 'Matiére' => 'pa_matiere', 'Format' => 'pa_format', 'Couleurs' => 'pa_couleur');
$attributes
= array('Univers' => 'pa_univers', 'Matiére' => 'pa_matiere', 'Format' => 'pa_format', 'Couleurs' => 'pa_couleur');
foreach (
$attributes
as
$key
=>
$value
) :
foreach (
$attributes
as
$key
=>
$value
) :
?>
?>
<div
class=
"filter-bloc"
>
<div class="
filter
-
bloc
<?
php
if
(
$_GET
[
$value
]
!=
''
)
echo
'active selected-filter'
;
?>
">
<div
class=
"header"
>
<div
class=
"header"
>
<p><span>
<?php
echo
$key
?>
</span></p>
<p><span>
<?php
echo
$key
?>
</span></p>
</div>
</div>
<?php
<?php
if
(
$value
==
'pa_couleur'
)
$terms
=
get_terms
(
$value
);
$terms
=
get_terms
(
$value
);
else
$terms
=
nap_attribute_by_category
(
$cateID
,
$value
);
//print_r($terms);
if
(
!
empty
(
$terms
)
&&
!
is_wp_error
(
$terms
))
:
if
(
!
empty
(
$terms
)
&&
!
is_wp_error
(
$terms
))
:
?>
?>
<div
class=
"bloc-content"
>
<div
class=
"bloc-content"
>
<ul
<?php
if
(
$value
==
'pa_couleur'
)
echo
'class = "list-color-filter clearfix"'
;
?>
>
<ul
<?php
if
(
$value
==
'pa_couleur'
)
echo
'class = "list-color-filter clearfix"'
;
?>
id=
"
<?php
echo
$value
;
?>
"
>
<?php
<?php
foreach
(
$terms
as
$term
)
:
foreach
(
$terms
as
$term
)
:
if
(
$value
==
'pa_couleur'
)
:
if
(
$value
==
'pa_couleur'
)
:
$color
=
get_field
(
'couleurs'
,
'pa_couleur_'
.
$term
->
term_id
);
$color
=
get_field
(
'couleurs'
,
'pa_couleur_'
.
$term
->
term_id
);
if
(
isset
(
$color
)
&&
strlen
(
$color
)
>
0
)
:
if
(
isset
(
$color
)
&&
strlen
(
$color
)
>
0
)
:
if
(
isset
(
$_GET
[
'pa_couleur'
])
&&
stristr
(
$_GET
[
'pa_couleur'
],
$color
))
:
$filter_class
=
'selected'
;
else
:
$filter_class
=
''
;
endif
;
?>
?>
<li
data-color =
"
<?php
echo
$color
;
?>
"
class=
"
<?php
echo
$term
->
name
;
?>
"
></li>
<li
data-color =
"
<?php
echo
$color
;
?>
"
class=
"
<?php
echo
$term
->
name
.
' '
.
$filter_class
;
?>
"
></li>
<?php
<?php
endif
;
endif
;
else
:
else
:
?>
?>
<li>
<?php
echo
$term
->
name
;
?>
</li>
<?php
if
(
isset
(
$_GET
[
'pa_format'
])
&&
stristr
(
$_GET
[
'pa_format'
],
$term
))
:
$filter_class
=
'selected'
;
else
:
$filter_class
=
''
;
endif
;
?>
<li
class=
"
<?php
echo
$filter_class
?>
"
>
<?php
echo
$term
;
?>
</li>
<?php
<?php
endif
;
endif
;
endforeach
;
endforeach
;
...
@@ -102,6 +141,7 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
...
@@ -102,6 +141,7 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
</div>
</div>
</div>
</div>
</div>
</div>
<?php
endif
;
?>
<?php
<?php
foreach
(
$child_category
as
$key
=>
$value
)
:
foreach
(
$child_category
as
$key
=>
$value
)
:
?>
?>
...
@@ -144,7 +184,7 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
...
@@ -144,7 +184,7 @@ $child_category = get_terms('product_cat', array('parent' => $cateID, 'child_of'
);
);
?>
?>
<?php
echo
nap_get_item
(
$id
,
$args
,
$current_page
,
$options
);
?>
<?php
echo
nap_get_item
(
$id
,
$args
,
$current_page
,
$options
,
$_GET
);
?>
<?php
<?php
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment