导航菜单
首页 > 实战seo » 正文

帝国当前栏目名去匹配数据库文章标题(当前页面标题和第一个关键词去匹配)

第一是整个数据库

[e:loop={'select * from [!db.pre!]ecms_news where title like "%'.$class_r[$GLOBALS['navclassid']][classname].'%" and titlepic !="" order by id desc ',0,24,0}]


限制只匹配三篇文章(整个数据库)
[e:loop={'select * from [!db.pre!]ecms_news where title like "%'.$class_r[$GLOBALS['navclassid']][classname].'%" and titlepic !=""order by id desc limit 3',0,24,0}]

当前栏目名去匹配文章标题
  [e:loop={'select * from [!db.pre!]ecms_news where classid=51 and title like "%'.$class_r[$GLOBALS['navclassid']][classname].'%" and titlepic !="" order by id desc ',0,24,0}]

4.根据当前页面第一个关键词去匹配文章标题

<? $key = explode(',',$navinfor[keyboard])[0];?>
[e:loop={'select * from [!db.pre!]ecms_news where title like "%'.$key.'%" and titlepic !=""order by id desc limit 10',0,24,0}]


4.根据当前页面标题去匹配文章标题
<? $key =$navinfor[title];?>
[e:loop={'select * from [!db.pre!]ecms_news where title like "%'.$key.'%" and titlepic !=""order by id desc limit 7',0,24,0}]

<li><a href="<?=$bqsr['titleurl']?>"  title="<?=$bqr['title']?>" target="_blank"><?=$bqr['title']?></a></li>
[/e:loop]

5.两步判断,优质用关键字第一个去匹配,如果不行就用开头标题截取二个字去匹配

<? 
$key = explode(',',$navinfor[keyboard])[0];
if(empty($key)){
    $key = mb_substr($navinfor[smalltext], 0, 2);
}

?>
[e:loop={'select * from [!db.pre!]ecms_news where title like "%'.$key.'%" and titlepic !=""order by id desc limit 10',0,24,0}]

6.截取用这个比较好

       <h3 class="widget-title">相关文章</h3>
          <ul>
<? 
$key = explode(',',$navinfor[keyboard])[0];
if(empty($key)){
    $key = mb_substr($navinfor[title], 0, 2,"UTF-8");
}
$key = mb_substr($navinfor[title], 0, 2,"UTF-8");
?>

[e:loop={'select * from [!db.pre!]ecms_news where title like "%'.$key.'%"  !=""order by id desc limit 10',0,24,0}]

            <li> <a href="<?=$bqsr['titleurl']?>"><?=$bqr['title']?></a></li>

     
          [/e:loop]

解读,如果截取第三个和第四个汉字,就第一个0改为2.,表示从第二个汉字后面截取2个字

第三和第五个汉字且不重复用下面这个,且每条取5条

    <? 
$key = explode(',',$navinfor[keyboard])[0];
if(empty($key)){
    $key = mb_substr($navinfor[title], 0, 2,"UTF-8");
}
$key = mb_substr($navinfor[title], 0, 2,"UTF-8");
?>
<?php
$idstring='';
$frist=1;
?>
[e:loop={'select * from [!db.pre!]ecms_news where title like "%'.$key.'%"  !=""order by id desc limit 5',0,24,0}]
<?php
          if($frist){
             $idstring.=$bqr['id'];
             $frist=0;
         }else{
            $idstring=$idstring.','.$bqr['id'];
         }
          ?>

            <li> <a href="<?=$bqsr['titleurl']?>"><?=$bqr['title']?></a></li>

     
          [/e:loop]
     <? 
$key = explode(',',$navinfor[keyboard])[0];
if(empty($key)){
    $key = mb_substr($navinfor[title], 3, 2,"UTF-8");
}
$key = mb_substr($navinfor[title], 3, 2,"UTF-8");
?>


[e:loop={'select * from [!db.pre!]ecms_news where title like "%'.$key.'%"  !="" and id not in('.$idstring.') order by id desc limit 5',0,24,0}]
            <li> <a href="<?=$bqsr['titleurl']?>"><?=$bqr['title']?></a></li>
<?php
          if($frist){
             $idstring.=$bqr['id'];
             $frist=0;
         }else{
            $idstring=$idstring.','.$bqr['id'];
         }
          ?>
     
          [/e:loop]

     <? 
$key = explode(',',$navinfor[keyboard])[0];
if(empty($key)){
    $key = mb_substr($navinfor[title], 5, 2,"UTF-8");
}
$key = mb_substr($navinfor[title], 5, 2,"UTF-8");
?>

[e:loop={'select * from [!db.pre!]ecms_news where title like "%'.$key.'%"  !="" and id not in('.$idstring.') order by id desc limit 5',0,24,0}]

            <li> <a href="<?=$bqsr['titleurl']?>"><?=$bqr['title']?></a></li>

     
          [/e:loop]

6.如果不行,且有点的话,用下面这个

<? 
$key = explode(',',$navinfor[keyboard])[0];
if(empty($key)){
    $key = mb_substr($navinfor[title], 0, 2,"UTF-8");
}
$key = mb_substr($navinfor[title], 0, 2,"UTF-8");
?>
<?php
$idstring='';
$frist=1;
?>
[e:loop={'select * from [!db.pre!]ecms_news where title like "%'.$key.'%"  !=""order by id desc limit 5',0,24,0}]
<?php
          if($frist){
             $idstring.=$bqr['id'];
             $frist=0;
         }else{
            $idstring=$idstring.','.$bqr['id'];
         }
          ?>

            <a href="<?=$bqsr['titleurl']?>"><?=$bqr['title']?></a>

     
          [/e:loop]
     <? 
$key = explode(',',$navinfor[keyboard])[0];
if(empty($key)){
    $key = mb_substr($navinfor[title], 3, 2,"UTF-8");
}
$key = mb_substr($navinfor[title], 3, 2,"UTF-8");
?>


[e:loop={'select * from [!db.pre!]ecms_news where title like "%'.$key.'%"  !="" and id not in('.$idstring.') order by id desc limit 5',0,24,0}]
            <a href="<?=$bqsr['titleurl']?>"><?=$bqr['title']?></a>
<?php
          if($frist){
             $idstring.=$bqr['id'];
             $frist=0;
         }else{
            $idstring=$idstring.','.$bqr['id'];
         }
          ?>
     
          [/e:loop]

     <? 
$key = explode(',',$navinfor[keyboard])[0];
if(empty($key)){
    $key = mb_substr($navinfor[title], 5, 2,"UTF-8");
}
$key = mb_substr($navinfor[title], 5, 2,"UTF-8");
?>

[e:loop={'select * from [!db.pre!]ecms_news where title like "%'.$key.'%"  !="" and id not in('.$idstring.') order by id desc limit 5',0,24,0}]

            <a href="<?=$bqsr['titleurl']?>"><?=$bqr['title']?></a>

     
          [/e:loop]

8.前三个关键字去匹配标题

      <ul>
<? $noid='0';?>
<? $keyarr = explode(',',$navinfor[keyboard]);?>
<? foreach($keyarr as $k=>$key){
     if($k>2) break;
?>

[e:loop={'select * from [!db.pre!]ecms_news where title like "%'.$key.'%" and titlepic !="" and id not in('.$noid.') order by id desc limit 5',0,24,0}]
<? $noid=$noid.','.$bqr['id'];?>
<li><a href="<?=$bqsr['titleurl']?>"  title="<?=$bqr['title']?>" target="_blank"><?=$bqr['title']?></a></li>
[/e:loop]


<? }?>

      </ul>

9.取第四和第五个关键每个五条,且不重复

    <ul>
<? foreach($keyarr as $k=>$key){
     if($k>2&&$k<5) {
?>

[e:loop={'select * from [!db.pre!]ecms_news where title like "%'.$key.'%" and titlepic !="" and id not in('.$noid.') order by id desc limit 5',0,24,0}]
<? $noid=$noid.','.$bqr['id'];?>
<li><a href="<?=$bqsr['titleurl']?>"  title="<?=$bqr['title']?>" target="_blank"><?=$bqr['title']?></a></li>
[/e:loop]


<? }}?>

      </ul>
收藏此文 赞一个 ( )
留言与评论(共有 0 条评论)
   
验证码: