phpcms 模板header包含action="lists"导致搜索结果错误的解决方案

2020-04-26 浏览:1941
phpcms 模板header包含action="lists"导致搜索结果错误的解决方案
评论:(0)复制地址

在搜索模板header中包含了

{pc:content action="lists" catid="14" num="12" order="listorder DESC"}
						{loop $data $r}
						<li><a href="{$r['url']}"><span>{$r['title']}</span></a></li>
						{/loop}
						{/pc}

搜索结果出现了错误,我们需要修改搜索相关文件

list.html

{loop $data_search $i $v}
                <li class="product-con-group-inner">
					<a href="{$v['url']}" title="{$v['title']}">
                  <div class="product-img"><span>{if $v[thumb]}<img src="{$v[thumb]}" alt="{$v[title]}">{else}<img src="{siteurl($siteid)}/images/layout/no_img.jpg" alt="{$v[title]}" />{/if}</span></div>
                  <div class="product-name">
                    <h5>{$v[title]}</h5>
                    <p></p>
                  </div>
                  </a>
				</li>
				 {/loop}
				  {if empty($data_search)}未找到结果{/if}

phpcms/modules/search/index.php 修改下面内容,注意原先的data全部修改为data1

//是否读取其他模块接口
				if($modelid) {
					$this->content_db->set_model($modelid);
					
					/**
					 * 如果表名为空,则为黄页模型
					 */
					if(empty($this->content_db->model_tablename)) {
						$this->content_db = pc_base::load_model('yp_content_model');
						$this->content_db->set_model($modelid);

					}

					if($setting['sphinxenable']) {
						$data_search = $this->content_db->listinfo($where, 'id DESC', 1, $pagesize);
						$pages = pages($totalnums, $page, $pagesize);
					} else {
						$data_search = $this->content_db->select($where, '*');
						$pages = $this->db->pages;
						$totalnums = $this->db->number;
					}
				
					//如果分词结果为空
					if(!empty($segment_q)) {
						$replace = explode(' ', $segment_q);
						foreach($replace as $replace_arr_v) {
							$replace_arr[] =  ''.$replace_arr_v.'';
						}
						foreach($data_search as $_k=>$_v) {
							$data_search[$_k]['title'] = str_replace($replace, $replace_arr, $_v['title']);
							$data_search[$_k]['description'] = str_replace($replace, $replace_arr, $_v['description']);
						}
					} else {
						foreach($data as $_k=>$_v) {
							$data_search[$_k]['title'] = str_replace($q, ''.$q.'', $_v['title']);
							$data_search[$_k]['description'] = str_replace($q, ''.$q.'', $_v['description']);
						}
					}
				} else {
					//读取专辑搜索接口
					$special_api = pc_base::load_app_class('search_api', 'special');
 					$data_search = $special_api->get_search_data($sids);
					$totalnums = count($data_search);
				}
			}
			$execute_time = execute_time();
			$pages = isset($pages) ? $pages : '';
			$totalnums = isset($totalnums) ? $totalnums : 0;
			$data_search = isset($data_search) ? $data_search : '';
			
			include	template('search','list');
		} else {
			include	template('search','index');
		}


评论:(0)复制地址
发布:苗景云 | 分类:IT技术&设计 | Tags:phpcms

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。