Hongmu Notes
Home Practical Collection Insert related articles in the middle of imperial cms articles (article page optimization, the effect is super good)
Practical Collection empire plugin

Insert related articles in the middle of imperial cms articles (article page optimization, the effect is super good)

Insert related articles in the middle of imperial cms articles (article page optimization, the effect is super good)

Everyone knows that this function can aggregate related articles. Since it is displayed in the middle of the text, it can not only improve the user experience, but also achieve optimization effects.

At present, I found that some high-authority websites are using this function, so I studied for several hours and wrote this tutorial!

It’s not just a little help for website optimization, I believe all the website optimization experts know it!

This feature was also suggested to me by a website optimization expert. I hope it will be helpful to all webmasters!

Whether you are a collection site, a regular article site, an information site, a product, novel or movie site, this function is suitable. Of course, the premise is that your website is an empire cms!

Effect preview:

ad1a1b7183223247

Insert a related article in the middle of the article, and you can set the number of articles

No complicated plug-ins are required, just follow the tutorial!

If not, you can contact me to help install it.

Tutorial steps:

Step 1: Install the code

Open the file /e/class/userfun.php

Put the following PHP function code into the second line

PHP function code:

 隐藏内容:付费阅读
function content_more_page($id,$stb,$content,$sign,$num=8,$biao = 'news'){
    global $empire,$dbtbpre;
    $is = $empire->fetch1("SELECT keyid FROM `phome_ecms_{$biao}_data_{$stb}` WHERE `id` = {$id} ");
    if(!empty($is['keyid'])){
    $is['keyid'] = rtrim($is['keyid'],",");
    $arr_keyid = explode(",",$is['keyid']);
    if(count($arr_keyid) > $num){
        $rand_keyid = array_rand($arr_keyid,$num);
        foreach($rand_keyid as $v){
            $more_id.= $arr_keyid[$v].",";
        }
        $more_id = rtrim($more_id,",");
    }else{
        $more_id = $is['keyid'];
    }
    $found_news = $empire->query("SELECT title,titleurl FROM `phome_ecms_{$biao}` WHERE id in({$more_id}) ORDER BY `id` DESC ");
    while($j=$empire->fetch($found_news))        //循环获取查询记录
    {
       $li.="<li class='more_li'><a href='{$j['titleurl']}' title='{$j['title']}'>{$j['title']}</a></li>";
    }
        
    $more_this_content = '<ul id="more_ul"><strong>也许对您有帮助</strong>'.$li."</ul>";
    return content_center($content,$more_this_content,$sign);
    }else{
        return $content;
    }
}

function content_center($content,$other,$sign){
    $y = $content;
    $n = floor(substr_count($content,$sign)/2);
    for ($i=1;$i<=$n;$i++){
        $pos = strpos($content,$sign);
        $content = substr($content,$pos+1);
        $pos_val=$pos+$pos_val+1;
    }
    $count = $pos_val-1;
    return substr($y,0,$count).$other.substr($y,$count);
    
}

PHP code for the second version:

Fixed array_rand function call asking the wrong question.

Added newstime judgment, suitable for websites that regularly publish articles!

 隐藏内容:付费阅读
<?php
//---------------------------用户自定义标签函数文件

function content_more_page($id,$stb,$content,$sign,$num=8,$biao = 'news'){
    global $empire,$dbtbpre;
    $is = $empire->fetch1("SELECT keyid FROM `phome_ecms_{$biao}_data_{$stb}` WHERE `id` = {$id} ");
    if(!empty($is['keyid'])){
	
    $is['keyid'] = rtrim($is['keyid'],",");
    $arr_keyid = explode(",",$is['keyid']);
	
    if(!empty($arr_keyid)){
        $num = count($arr_keyid) >= $num ? count($arr_keyid) : $num;
        $rand_keyid = array_rand($arr_keyid,$num);
        foreach($rand_keyid as $v){
            $more_id.= $arr_keyid[$v].",";
        }
        $more_id = rtrim($more_id,",");
    }else{
        return $content;
    }
    
    $found_news = $empire->query("SELECT title,titleurl FROM `phome_ecms_{$biao}` WHERE id in ({$more_id}) and newstime <= ".time()." ORDER BY `id` DESC ");
    
    while($j=$empire->fetch($found_news))        //循环获取查询记录
    {
        $shows = !empty($j['title'])?true:false;
        $li.="<li class='more_li'><a href='{$j['titleurl']}' title='{$j['title']}'>{$j['title']}</a></li>";
    }
        $more_this_content = '<ul id="more_ul"><strong>也许对您有帮助</strong>'.$li."</ul>";
        if($shows){
            return content_center($content,$more_this_content,$sign);
        }else{
            return $content;
        }
    
	}else{
        return $content;
    }
}

function content_center($content,$other,$sign){
    $y = $content;
    $n = floor(substr_count($content,$sign)/2);
    for ($i=1;$i<=$n;$i++){
        $pos = strpos($content,$sign);
        $content = substr($content,$pos+1);
        $pos_val=$pos+$pos_val+1;
    }
    $count = $pos_val-1;
    return substr($y,0,$count).$other.substr($y,$count);
    
}

Step 2: Replace the call template in the article template

The original calling method is: [!--newstext--]

Now let's change it to this:

 隐藏内容:付费阅读
<?=content_more_page($navinfor['id'],$navinfor['stb'],$navinfor['newstext'],'</p>','news')?>

The first parameter is the article id

The second parameter is the schedule id corresponding to the content.

The third one is news content

The fourth is to add it after the label (generally no need to modify)

What is the fourth table? It is usually the news table.

Step 3: Enable the empire’s aggregation function

The activation method is as shown in the figure:

 隐藏内容:付费阅读

ad1a1b7183224927

Required conditions: Each article must be set with keywords, and each keyword is separated by English, because only in this way can the aggregation function of Empire be successfully aggregated.

If your imperial website does not have keywords set, but the number of articles is very large, then you can contact me to help you solve it.

Solution: Use the word segmentation API to segment the title (paid separately)

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

EmpireCMS AutoTitlePic – Automatically generates title images

EmpireCMS AutoTitlePic – Automatically generates title images Practical Collection empire plugin

AutoTitlePic – a plugin that automatically generates article title images. When building a website, image copyright issues often arise; in such cases, having a plugin to generate thumbnails becomes extremely important! I have customized this plugin by adding a scheduled generation feature, allowing images to be automatically generated during periods of low site traffic – this can be seamlessly integrated with the scheduled tasks functionality in Baota. Key features: 1. Easy installation and simple to use; compatible with both existing and new websites. 2....
👁 419
Empire CMS 7.5 Baidu Active/Batch Push Plugin

Empire CMS 7.5 Baidu Active/Batch Push Plugin Practical Collection empire plugin

This plugin is compatible with EmpireCMS 7.5 and 7.2 (UTF-8 versions); its installation and uninstallation process is simple and straightforward. Many novice webmasters using EmpireCMS may often struggle with how to automatically push newly published articles to Baidu in real time. If website articles are not regularly submitted to Baidu, website indexing will be significantly delayed, which can negatively impact SEO performance. Especially for content aggregators, manually submitting articles would be a tedious and time-consuming task...
👁 341
After running the Empire CMS automatic installation script, the system will redirect you to the login page.

After running the Empire CMS automatic installation script, the system will redirect you to the login page. Practical Collection empire plugin

It's so annoying – every time I need to install the Empire CMS template, I have to manually delete the `install.lock` file and then proceed step by step! After completing each step, I still have to manually enter the database credentials and initial password! This is really frustrating! So, I wrote a PHP script with the following basic functionality: it eliminates the need to manually access the `/e/install` directory or delete the `lock` file; when the script is run, it automatically installs Empire CMS and then redirects the user to the Empire CMS homepage...
👁 230
Empire Toolbox V1.0

Empire Toolbox V1.0 Practical Collection empire plugin

As a webmaster who frequently uses Empire CMS, I often find certain operations to be particularly cumbersome! For example, I might want to change the Empire CMS database table prefix; or perhaps I want to batch modify the thumbnails for all articles collected from an external source; or if the images in the collected articles have become invalid, I might want to randomly replace them with new images; or I might want to batch delete other unnecessary tables from the Empire CMS database; or perhaps I've forgotten my Empire CMS admin panel password...
👁 442
EmpireCMS Batch Column Addition Plugin

EmpireCMS Batch Column Addition Plugin Practical Collection empire plugin

1. Powerful functionality: Automatically generates Pinyin-based table of contents; allows for quick, unified configuration of parent categories; supports recognition of custom parent categories. 2. User-friendly interface: Except for category names and table of contents settings, all other features follow the same configuration methods as those provided by the system itself, making it easy to get started. Custom category fields can also be configured in bulk. ******************** Installation Guide ********************
👁 332
What is the optimal number of data sub-tables for EmpireCMS? How should published data be distributed across sub-tables? How can a million records in EmpireCMS be evenly distributed across multiple sub-tables?

What is the optimal number of data sub-tables for EmpireCMS? How should published data be distributed across sub-tables? How can a million records in EmpireCMS be evenly distributed across multiple sub-tables? Program Notes Empire cms Practical Collection empire plugin

How many data rows should be split into separate tables for EmpireCMS? 1. For a database size of 50 GB, it is advisable to create a new main table; 2. For a dataset of 50,000 rows or more, create a new secondary table and set this newly created secondary table as the current storage table; [Some recommend splitting the entire dataset into a single table when the data volume reaches 100,000 rows.] An excessively large dataset has resulted in extremely high I/O read/write operations on the MySQL database, leading to excessive server load. This is particularly noticeable when performing backend operations in EmpireCMS – especially for sections with large data volumes; this was the case on my website before I implemented table partitioning...
👁 683

Recommended reading

(PC+WAP) Biotechnology Company Website Template – With Three-Level Sub-Categories – 0928

(PC+WAP) Biotechnology Company Website Template – With Three-Level Sub-Categories – 0928 Practical Collection pbootcms Template

A PbootCMS website template designed for biotechnology companies, featuring three-level sub-collections. Its professional and tech-oriented design is ideal for biotechnology and pharmaceutical R&D enterprises to showcase their technical expertise and product portfolio. This template helps biopharmaceutical companies establish a professional online brand image. Template Overview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn | Related Articles: Pboo...
👁 33
Responsive Academy Research Institute Website Template 1164

Responsive Academy Research Institute Website Template 1164 Practical Collection Yiyou template

An eYouCMS responsive website template designed specifically for Chinese Academy of Sciences and research institutes. Its modern, professional design effectively showcases research projects, technological achievements, expert teams, and institutional strengths. This template helps research institutions build an authoritative online presence and attract potential partners. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for eYouCMS | eYouCMS...
👁 58
(Adaptive Mobile Version) Construction Website Template – Download Group-wide Corporate Website Source Code – 0929

(Adaptive Mobile Version) Construction Website Template – Download Group-wide Corporate Website Source Code – 0929 Practical Collection pbootcms Template

A PbootCMS website template designed for construction companies and large corporations, supporting mobile access. Its sophisticated and professional design makes it ideal for construction groups or engineering firms to showcase their corporate strength and project portfolios. This template serves as an essential tool for large construction enterprises to establish their brand image online. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn | Related Articles...
👁 50
Departmental Association Website Template 1165

Departmental Association Website Template 1165 Practical Collection Yiyou template

This EyouCMS template is ideal for departmental or association-based websites. Its professional and sophisticated design effectively showcases departmental functions, association services, industry trends, and member activities, helping industry associations establish an online information exchange platform. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS (EyouCms)...
👁 33
(Adaptive Mobile Version) Chemical Engineering Website Templates – Nano Fiber Website Source Code Download – 0930

(Adaptive Mobile Version) Chemical Engineering Website Templates – Nano Fiber Website Source Code Download – 0930 Practical Collection pbootcms Template

A PbootCMS website template for the chemical industry and nanofiber applications, supporting mobile access. Its professional, tech-oriented design is ideal for chemical companies and new materials firms to showcase their products and technologies. This template helps chemical material enterprises demonstrate their R&D capabilities online and attract industry clients. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn | Related Articles...
👁 40
Combine multiple Python articles into a single article.

Combine multiple Python articles into a single article. Language Notes python

A friend mentioned needing to combine multiple Markdown-format files or articles into a single document. The requirement is quite simple: merge several TXT files from a folder into one document in sequential order. The output format should be as follows: <h3>Document 1 – File Name</h3> – Document 1 Content <h3>Document 2 – File Name</h3> – Document 2 Content <h3>Document 3 – File Name...
👁 201