有同学问怎么在Chevereto首页加上上传图片总数量统计,这里我就给出方法,只要在一个文件里加上几行代码就能解决。

Chevereto - 首页加入上传图片总数量统计

第一种方法

在文件/app/themes/Peafowl/views/index.php 合适位置加入以下代码:

  1. <div id=“home-cover” data-content=“follow-scroll-opacity”>
  2. <?php G\Render\include_theme_file(‘snippets/homepage_cover_slideshow’); ?>
  3. <div id=“home-cover-content” class=“c20 fluid-column center-box padding-left-10 padding-right-10”>
  4. <?php CHV\Render\show_banner(‘home_before_title’, (function_exists(‘get_list’) ? get_list()->sfw : true)); ?>
  5. <h1><?php echo CHV\getSetting(‘homepage_title_html’) ?: _s(‘Upload and share your images.’); ?></h1>
  6. <h1>本站共托管 <?php
  7. $stats = CHV\Stat::getTotals();
  8. echo $stats[‘images’] > 999999 ? $stats[‘images’] : number_format($stats[‘images’]); // Will output the total n° images
  9. ?> 张图片</h1>

第二种方法

1、新建文件–保存为 count.php

  1. <?php
  2. error_reporting(0);
  3. $con = mysql_connect(“localhost”, “数据库用户名”, “数据库密码”);
  4. if (!$con)
  5. {
  6. die(‘Could not connect: ‘ . mysql_error());
  7. }
  8. $db_selected = mysql_select_db(“tu”,$con);
  9. $sql = “SELECT * FROM chv_images”;
  10. $result = mysql_query($sql,$con);
  11. echo mysql_num_rows($result);
  12. mysql_close($con);
  13. ?>

2、放在 app/themes/Peafowl/views/index.php 文件中的合适位置

  1. <?php
  2. $data = file_get_contents(https://网站域名/count.php&#8217;);
  3. ?>
  4. <p>本站已托管图片 <?php echo $data ?></p>