|
2 | 2 |
|
3 | 3 |
|
4 | 4 | class VFA_ModelCommonSeo extends VFA_Model { |
| 5 | + public function addUrl($url, $type, $id) |
| 6 | + { |
| 7 | + global $wpdb; |
| 8 | + |
| 9 | + $sql = 'SELECT * |
| 10 | + FROM |
| 11 | + `'.$wpdb->prefix.'vuefront_url` |
| 12 | + WHERE url LIKE \''.$url.'\''; |
| 13 | + |
| 14 | + $result = $wpdb->get_row( $sql ); |
| 15 | + if (!$result) { |
| 16 | + $wpdb->insert( $wpdb->prefix.'vuefront_url' , array("url" => $url, "id" => $id, "type" => $type)); |
| 17 | + } |
| 18 | + } |
5 | 19 | public function get_category_by_url($url) { |
6 | 20 | foreach( (get_terms()) as $category) { |
7 | 21 | $keyword = str_replace(get_site_url(), '', get_term_link((int)$category->term_id)); |
8 | 22 | $keyword = trim($keyword, '/?'); |
9 | 23 | $keyword = trim($keyword, '/'); |
| 24 | + var_dump($keyword); |
10 | 25 |
|
11 | | - if ( '/' . $keyword == $url ) |
12 | | - |
| 26 | + if ( $keyword == $url ) { |
| 27 | + return array('id' => $category->term_id, 'slug' => $category->slug, 'type' => $category->taxonomy); |
| 28 | + } |
| 29 | + if ( '/' . $keyword == $url ) { |
| 30 | + return array('id' => $category->term_id, 'slug' => $category->slug, 'type' => $category->taxonomy); |
| 31 | + } |
| 32 | + if ( '/?' . $keyword == $url ) { |
13 | 33 | return array('id' => $category->term_id, 'slug' => $category->slug, 'type' => $category->taxonomy); |
| 34 | + } |
| 35 | + |
14 | 36 | } |
15 | 37 | return false; |
16 | 38 | } |
17 | 39 | public function searchKeyword($url) { |
18 | | - $search = url_to_postid($url); |
19 | | - $type = ''; |
20 | | - |
21 | | - if ($search != 0) { |
22 | | - if (get_post_type($search) == 'post') { |
23 | | - $type = 'post'; |
24 | | - } else if (get_post_type($search) == 'page') { |
25 | | - $type = 'page'; |
26 | | - } else { |
27 | | - $type = 'product'; |
28 | | - } |
29 | | - } else { |
30 | | - $search = $this->get_category_by_url($url); |
31 | | - if ($search) { |
32 | | - if ($search['type'] == 'category') { |
33 | | - $type = 'blog-category'; |
34 | | - $search = $search['id']; |
35 | | - } else if($search['type'] == 'pwb-brand') { |
36 | | - $type = 'manufacturer'; |
37 | | - $search = $search['slug']; |
38 | | - } else { |
39 | | - $type='category'; |
40 | | - $search = $search['id']; |
41 | | - } |
42 | | - } else { |
43 | | - $search = ''; |
44 | | - } |
45 | 40 |
|
46 | | - } |
| 41 | + global $wpdb; |
| 42 | + |
| 43 | + $sql = 'SELECT * |
| 44 | + FROM |
| 45 | + `'.$wpdb->prefix.'vuefront_url` |
| 46 | + WHERE url LIKE \''.$url.'\''; |
47 | 47 |
|
| 48 | + $result = $wpdb->get_row( $sql ); |
| 49 | + if (!$result) { |
| 50 | + return array( |
| 51 | + 'id' => '', |
| 52 | + 'type' => '', |
| 53 | + 'url' => $url |
| 54 | + ); |
| 55 | + } |
48 | 56 | return array( |
49 | | - 'id' => $search, |
50 | | - 'type' => $type, |
| 57 | + 'id' => $result->id, |
| 58 | + 'type' => $result->type, |
51 | 59 | 'url' => $url |
52 | 60 | ); |
53 | 61 | } |
|
0 commit comments