@@ -48,14 +48,14 @@ function results() {
48
48
}
49
49
50
50
$ menuSql = new menuSQL ();
51
- $ results = $ menuSql ->getMenus ($ options );
51
+ $ results = $ menuSql ->get ($ options );
52
52
53
53
//count the number of child menus (subcategories) for each category
54
- if (isset ($ results ['menus ' ])) {
54
+ if (isset ($ results ['menu ' ])) {
55
55
$ productIds = [];
56
56
$ postIds = [];
57
57
58
- foreach ($ results ['menus ' ] as $ taxonomy_item_id => &$ category ) {
58
+ foreach ($ results ['menu ' ] as $ taxonomy_item_id => &$ category ) {
59
59
$ parent_id = $ category ['parent_id ' ] ?? false ;
60
60
$ type = $ category ['type ' ] ?? 'link ' ;
61
61
@@ -64,7 +64,7 @@ function results() {
64
64
}
65
65
66
66
if ($ parent_id > 0 ) {
67
- $ parent = &$ results ['menus ' ][$ parent_id ];
67
+ $ parent = &$ results ['menu ' ][$ parent_id ];
68
68
69
69
if (isset ($ parent ['children ' ])) {
70
70
$ parent ['children ' ]++;
@@ -78,11 +78,13 @@ function results() {
78
78
}
79
79
80
80
if ($ type == 'product ' ) {
81
- $ productIds [$ taxonomy_item_id ] = $ category ['item_id ' ];
81
+ $ productIds [$ taxonomy_item_id ] = $ category ['item_id ' ];
82
+ $ taxonomyProducts [$ category ['item_id ' ]][] = $ taxonomy_item_id ;
82
83
}
83
84
84
- if ($ type == 'post ' || $ type == 'page ' ) {
85
- $ postIds [$ taxonomy_item_id ] = $ category ['item_id ' ];
85
+ if (($ type == 'post ' || $ type == 'page ' ) && $ category ['item_id ' ]) {
86
+ $ postIds [$ category ['item_id ' ]] = $ category ['item_id ' ];
87
+ $ taxonomyPosts [$ category ['item_id ' ]][] = $ taxonomy_item_id ;
86
88
}
87
89
}
88
90
@@ -98,14 +100,14 @@ function results() {
98
100
$ products = $ productSql ->getAll ($ productOptions );
99
101
100
102
if (isset ($ products ['products ' ]) && $ products ['products ' ]) {
101
- $ productTaxonomy = array_flip ($ productIds );
102
-
103
103
foreach ($ products ['products ' ] as $ product ) {
104
- $ taxonomy_item_id = $ productTaxonomy [$ product ['product_id ' ]];
105
- $ category = &$ results ['menus ' ][$ taxonomy_item_id ];
106
- $ route = "product/ {$ category ['type ' ]}/index " ;
107
- $ category ['url ' ] = url ($ route , ['slug ' => $ product ['slug ' ]]);
108
- $ category ['name ' ] = $ product ['name ' ];
104
+ foreach ($ taxonomyPosts [$ product ['product_id ' ]] as $ taxonomy_item_id ) {
105
+ $ taxonomy_item_id = $ productTaxonomy [$ product ['product_id ' ]];
106
+ $ category = &$ results ['menu ' ][$ taxonomy_item_id ];
107
+ $ route = "product/ {$ category ['type ' ]}/index " ;
108
+ $ category ['url ' ] = url ($ route , ['slug ' => $ product ['slug ' ], 'product_id ' => $ product ['product_id ' ]]);
109
+ $ category ['name ' ] = $ product ['name ' ];
110
+ }
109
111
}
110
112
}
111
113
}
@@ -121,15 +123,15 @@ function results() {
121
123
$ postSql = new postSql ();
122
124
$ posts = $ postSql ->getAll ($ postOptions );
123
125
124
- if (isset ($ posts ['posts ' ]) && $ posts ['posts ' ]) {
125
- $ postTaxonomy = array_flip ( $ postIds );
126
-
127
- foreach ( $ posts [ ' posts ' ] as $ post ) {
128
- $ taxonomy_item_id = $ postTaxonomy [ $ post [ ' post_id ' ]] ;
129
- $ category = & $ results [ ' menus ' ][ $ taxonomy_item_id ] ;
130
- $ route = " content/ { $ category ['type ' ]} /index " ;
131
- $ category ['url ' ] = url ( $ route , [ ' slug ' => $ post ['slug ' ]]) ;
132
- $ category [ ' name ' ] = $ post [ ' name ' ];
126
+ if (isset ($ posts ['post ' ]) && $ posts ['post ' ]) {
127
+ foreach ( $ posts [ ' post ' ] as $ post ) {
128
+ foreach ( $ taxonomyPosts [ $ post [ ' post_id ' ]] as $ taxonomy_item_id ) {
129
+ $ category = & $ results [ ' menu ' ][ $ taxonomy_item_id ];
130
+ $ route = " content/ { $ category [ ' type ' ]} /index " ;
131
+ $ url = url ( $ route , [ ' slug ' => $ post [ ' slug ' ], ' post_id ' => $ post [ ' post_id ' ]]) ;
132
+ $ category ['url ' ] = $ url ;
133
+ $ category ['name ' ] = $ post ['name ' ] ;
134
+ }
133
135
}
134
136
}
135
137
}
@@ -144,9 +146,9 @@ function results() {
144
146
function request (&$ results , $ index = 0 ) {
145
147
$ currentUrl = getCurrentUrl ();
146
148
147
- if (isset ($ results ['menus ' ])) {
148
- foreach ($ results ['menus ' ] as $ taxonomy_item_id => &$ category ) {
149
- $ category ['active ' ] = ($ category ['url ' ] === $ currentUrl );
149
+ if (isset ($ results ['menu ' ])) {
150
+ foreach ($ results ['menu ' ] as $ taxonomy_item_id => &$ category ) {
151
+ $ category ['active ' ] = isset ( $ category [ ' url ' ]) && ($ category ['url ' ] === $ currentUrl );
150
152
}
151
153
}
152
154
0 commit comments