Zblog search page beautification and search result paging tutorial

Source: Internet
Author: User
Tags foreach php file

The search result page of zblog php calls a single page, which cannot be customized or paged. It is ugly and humane. The Search Plus plug-in can optimize the search result page, and supports calling index templates and reserved Search templates (provided that the subject is available). It supports search word highlighting. The most important thing is that the list can be customized.

Zblog php search page beautification and search result paging

Plugin installation:

Search for Search Plus in the application center and install it directly.

Modify the plugin:

1. By default, this plug-in only optimizes the search interface, but does not support paging. You need to modify this plug-in when querying search results;

2. Edit the include. Php file under zb_users/plugin/SearchPlus/, locate about 40 lines of the plug-in, and change the query statement:

$ Pagebar = new Pagebar ('{% host %} search. php? {Q = '. $ q.'} & {page = % page %} ', false );
$ Pagebar-> PageCount = $ zbp-> displaycount;
$ Pagebar-> PageNow = (int) GetVars ('page', 'Get') = 0? 1 :( int) GetVars ('page', 'Get ');
$ Pagebar-> PageBarCount = $ zbp-> pagebarcount;
 
$ Articles = $ zbp-> GetArticleList (
'*',
$ W,
Array ('log _ posttime' => 'desc'), array ($ pagebar-> PageNow-1) * $ pagebar-> PageCount, $ pagebar-> PageCount ),
Array ('pagebar '=> $ pagebar ),
Null
);

Find the plug-in's 70 lines and change it:


$ Zbp-> template-> SetTags ('pagebar ', $ pagebar );

The following code overwrites all the code in the include. Php file:


<? Php
Require dirname (_ FILE _). DIRECTORY_SEPARATOR. 'Function'. DIRECTORY_SEPARATOR. 'Searchstr. Php ';
# Register a plug-in
RegisterPlugin ("SearchPlus", "ActivePlugin_SearchPlus ");
 
Function ActivePlugin_SearchPlus (){
Add_Filter_Plugin ('filter _ Plugin_Search_Begin ', 'searchplus _ main ');
 
}
 
Function SearchPlus_Main (){
Global $ zbp;
 
Foreach ($ GLOBALS ['filter _ Plugin_ViewSearch_Begin '] as $ fpname => & $ fpsignal ){
$ Fpreturn = $ fpname ();
If ($ fpsignal = PLUGIN_EXITSIGNAL_RETURN ){
$ Fpsignal = PLUGIN_EXITSIGNAL_NONE; return $ fpreturn;
        }
    }
 
If (! $ Zbp-> CheckRights ($ GLOBALS ['action']) {Redirect ('./');}
 
$ Q = trim (htmlspecialchars (GetVars ('Q', 'Get ')));
$ Qc = '<B style = \ 'color: red \'> '. $ q.' </B> ';
 
$ Articles = array ();
$ Category = new Metas;
$ Author = new Metas;
$ Tag = new Metas;
 
// $ Type = 'post-search ';
 
$ Zbp-> title = $ zbp-> lang ['MSG '] ['search'].' & quot; '. $ q.' & quot ;';
 
$ Template = $ zbp-> option ['zc _ INDEX_DEFAULT_TEMPLATE '];
 
If (isset ($ zbp-> templates ['search']) {
$ Template = 'search ';
    }
 
$ W = array ();
$ W [] = array ('=', 'log _ type', '0 ');
If ($ q ){
$ W [] = array ('search', 'log _ content', 'log _ intro', 'log _ title', $ q );
} Else {
Redirect ('./');
    }
 
If (! ($ Zbp-> CheckRights ('articleall') & $ zbp-> CheckRights ('pageall '))){
$ W [] = array ('=', 'log _ status', 0 );
    }
 
$ Pagebar = new Pagebar ('{% host %} search. php? {Q = '. $ q.'} & {page = % page %} ', false );
$ Pagebar-> PageCount = $ zbp-> displaycount;
$ Pagebar-> PageNow = (int) GetVars ('page', 'Get') = 0? 1 :( int) GetVars ('page', 'Get ');
$ Pagebar-> PageBarCount = $ zbp-> pagebarcount;
 
$ Articles = $ zbp-> GetArticleList (
'*',
$ W,
Array ('log _ posttime' => 'desc'), array ($ pagebar-> PageNow-1) * $ pagebar-> PageCount, $ pagebar-> PageCount ),
Array ('pagebar '=> $ pagebar ),
Null
);
Foreach ($ articles as $ article ){
$ Intro = preg_replace ('/[\ r \ n \ s] +/', '', trim (SubStrStartUTF8 (TransferHTML ($ article-> Content, '[nohtml]'), $ q, 170 )). '... ');
$ Article-> Intro = str_ireplace ($ q, $ qc, $ intro );
$ Article-> Title = str_ireplace ($ q, $ qc, $ article-> Title );
    }
 
$ Zbp-> header. = '<meta name = "robots" content = "noindex, follow"/>'. "\ r \ n ";
$ Zbp-> template-> SetTags ('title', $ zbp-> title );
$ Zbp-> template-> SetTags ('Articles ', $ articles );
// $ Zbp-> template-> SetTags ('type', $ type );
$ Zbp-> template-> SetTags ('page', 1 );
$ Zbp-> template-> SetTags ('pagebar ', $ pagebar );
 
If (isset ($ zbp-> templates ['search']) {
$ Zbp-> template-> SetTemplate ($ template );
} Else {
$ Zbp-> template-> SetTemplate ('index ');
    }
 
Foreach ($ GLOBALS ['filter _ Plugin_ViewList_Template '] as $ fpname => & $ fpsignal ){
$ Fpreturn = $ fpname ($ zbp-> template );
    }
 
$ Zbp-> template-> Display ();
RunTime ();
Die ();
}
 
Function InstallPlugin_SearchPlus (){
Global $ zbp;
 
}
 
Function UninstallPlugin_SearchPlus (){
Global $ zbp;
 
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.