doumiebiao6827 2018-10-26 20:56
浏览 30

编写PHP脚本以选择Codeigniter上的特殊生成缩略图信息

this is actually a very complicated question so i'll start to explain it.

  1. I have a CMS called 'FusionCMS' which uses Codeigniter.

  2. It Dynamically Generate the pages ( like news ) so they looks like domain.com/news/1 or /2 etc.. but that folders actually doesn't really exist.

  3. There is header.tpl file in view file which contains the meta tags.

  4. I make a PHP script to select special text from database to be as og tags.

  5. what i means with oh tags are the facebook meta tags exp : og:title - og:description.

  6. I want them to be selected depends on the page link ( exp if it's /news/11 ) than to select the ID 11 from database which will have title and content which will be what i need.

This are the codes ( PHP is missing the selection from URL and some modifications ). The TPL file is very big so i'll just put some of it.

PHP

if(isset($_GET['post'])) {
    $postid = $_GET['post'];
    $conn = mysqli_connect("127.0.0.1","root","ascent","fusioncms");
    $stmt = $conn->prepare("SELECT title, description FROM news WHERE id = ?");
    $stmt->bind_param("i", $postid);
    $stmt->execute();
    $stmt->bind_result($title, $message);
    $stmt->store_result();
    if($stmt->num_rows > 0) {
        while($stmt->fetch()) {
            echo "<meta name='og:title' content='".$title."'>";
            echo "<meta name='og:description' content='".$message."'>";
        }
    }
}else{
    echo "<meta name='og:title' content='Example Page for JadaDev'>";
    echo "<meta name='og:description' content='Some random description'>";
}

This is the TPL file ( header.tpl )

 <!-- Custom Scripts -->
    <meta property="og:title" content="{$title}"/>
    <meta property="og:type" content="website" />
    <meta property="og:url" content="{$path}"/>
    <meta property="og:image" content="http://127.0.0.1/application/themes/default/images/tam.png"/>
    <meta property="og:site_name" content="حزب تيار المحبة"/>
    <meta property="fb:app_id" content="2217370698541973" />
    <meta property="fb:admins" content="John.Evenetcha"/>
    <meta property="og:description" content="{$title}"/>
    <!-- End of Custom -->
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 个人网站被恶意大量访问,怎么办
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)