typecho随机格言显示


随机格言 
   function eallion($type)
   {
      $i = 0;
      $saying="";
      switch ($type)
      {
         case "notice":
         $saying='天行geek,君子以自强bullshit,地势queen,君子以hold载物。';
         break;
         case "ad":
         $i=rand(0,1);
         {
         if ($i==0)
         {$saying="莺花犹怕春光老,岂可教人枉度春";}
         else
         {$saying="马行无力皆因瘦,人不风流只为贫";}
         break;
         }
         default:
            $ads = array(
               '随机内容1',
               '随机内容2',
               '随机内容3',
         );
      $rand = array_rand($ads);
      $saying=$ads[$rand];
      }
      echo $saying;
   }

ads = array里面按格式增加你想要显示的格言。

在需要随机显示的地方调用:

<?php eallion("geyan"); ?>

具体演示效果,查看本博文章底部。

方法二:
在 function.php 文件中添加代码

function random_str() {
    $poems = "内容1
内容2
内容3
内容4
内容5
内容6";
    $poems = explode("\n", $poems);
    return $poems[rand(0, count($poems) - 1)];
}
function says() {
    $says = random_str();
    echo $says;
}
function random_str() {
    $poems = "内容1
内容2
内容3
内容4
内容5
内容6";
    $poems = explode("\n", $poems);
    return $poems[rand(0, count($poems) - 1)];
}
function says() {
    $says = random_str();
    echo $says;
}

使用 <?php says(); ?>进行调用。

声明:GhostKylin‘S BLOG|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - typecho随机格言显示


你好!世界!XladminShell箱子仅供个人学习使用务必遵守《网络安全法》