1.多图参数整合
foreach ($files[‘name‘] as $key => $value) { if ($files[‘name‘][$key] && !preg_match(‘/[\x{4e00}-\x{9fa5}]/u‘, $files[‘name‘][$key]) > 0){ $file = array( ‘name‘ => $files[‘name‘][$key], ‘type‘ => $files[‘type‘][$key], ‘tmp_name‘ => $files[‘tmp_name‘][$key], ‘error‘ => $files[‘error‘][$key], ‘size‘ => $files[‘size‘][$key] ); $_FILES = array("up_file" => $file); foreach ($_FILES as $file => $array) { $newupload = my_handle_attachment($file, $pid = 0); } $attach_id[] = $newupload; $name[] = $files[‘name‘][$key]; $type[] = $files[‘type‘][$key]; }else{ echo 3 ;exit; } }my_handle_attachment():为一般单图上传返回附件id
2.文件下载参考
//文件下载 header("Content-type:text/html;charset=utf-8"); $file_name = $_REQUEST[‘file‘]; //用以解决中文不能显示出来的问题 $file_name=iconv("utf-8","gb2312",$file_name); $file_sub_path=$_SERVER[‘DOCUMENT_ROOT‘].get_stylesheet_directory_uri(); $file_path=$file_sub_path.$file_name; //首先要判断给定的文件存在与否 if(!file_exists($file_path)){ echo "没有该文件文件"; return ; } $fp=fopen($file_path,"r"); $file_size=filesize($file_path); //下载文件需要用到的头 Header("Content-type: application/octet-stream"); Header("Accept-Ranges: bytes"); Header("Accept-Length:".$file_size); Header("Content-Disposition: attachment; filename=".$file_name); $buffer=1024; $file_count=0; //向浏览器返回数据 while(!feof($fp) && $file_count<$file_size){ $file_con=fread($fp,$buffer); $file_count+=$buffer; echo $file_con; } fclose($fp);
3.自定义分类查询
//自定义分类查询 $paged = 1; if ( get_query_var(‘paged‘) ) $paged = get_query_var(‘paged‘); if ( get_query_var(‘page‘) ) $paged = get_query_var(‘page‘); $posts_per_page = get_option(‘posts_per_page‘); $args = array( ‘post_type‘ => ‘post‘, //自定义文章类型 ‘posts_per_page‘=> 2, ‘tax_query‘ => array( array( ‘taxonomy‘ => ‘category‘, //调用自定义分类法 ‘field‘ => ‘cat‘, // ‘terms‘ => $term_arr[‘term_id‘] ) ), ‘paged‘ => $paged ); query_posts($args); if (have_posts()) : while (have_posts()) : the_post(); wp_reset_query();
4.自定义字段筛选
$posts_per_pages = get_option(‘posts_per_page‘); //$posts_per_pages = 1; $paged = 1; if ( get_query_var(‘paged‘) ) $paged = get_query_var(‘paged‘); if ( get_query_var(‘page‘) ) $paged = get_query_var(‘page‘); if(!empty($get_crowd) || !empty($get_xueke) || !empty($get_field) || !empty($get_app) ){ if(!empty($get_crowd)){ $crowd_array = array( ‘taxonomy‘ => ‘cat_crowd‘, ‘field‘ => ‘term_id‘, ‘terms‘ => $get_crowd ); } if(!empty($get_xueke)){ $xueke_array = array( ‘taxonomy‘ => ‘cat_xueke‘, ‘field‘ => ‘term_id‘, ‘terms‘ => $get_xueke ); } if(!empty($get_field)){ $field_array = array( ‘taxonomy‘ => ‘cat_field‘, ‘field‘ => ‘term_id‘, ‘terms‘ => $get_field ); } if(!empty($get_app)){ $app_array = array( ‘taxonomy‘ => ‘cat_application‘, ‘field‘ => ‘term_id‘, ‘terms‘ => $get_app ); } $args = array( ‘posts_per_page‘ => $posts_per_pages, ‘orderby‘ => $order, ‘order‘ => ‘desc‘, ‘post_type‘ => ‘type_product‘, ‘paged‘ => $paged, ‘post_status‘ => ‘publish‘, ‘tax_query‘ => array( ‘relation‘ => ‘AND‘, $crowd_array, $xueke_array, $field_array, $app_array, ) ); }else{ $args = array( ‘post_type‘ => ‘type_product‘, //自定义文章类型 ‘orderby‘ => $order, ‘order‘ => ‘desc‘, ‘posts_per_page‘ => $posts_per_pages, ‘paged‘ => $paged ); } query_posts($args); if (have_posts()) : ?><?php while (have_posts()) : the_post();
<?php endwhile;?> <?php else: ?> <div class="rock_list"> <p class="n_center"><?php _e(‘未找到内容‘,‘kepress‘); ?></p> </div> <?php endif; ?> </ul> <div class="page_wrap"> <?php of_pagenavi(999); ?> </div> <?php wp_reset_query(); ?>
5.loop 分页参考
function of_pagenavi( $settings ) { $s = wp_parse_args( $settings, array( ‘range‘ => ‘5‘, ‘before‘ => ‘‘, ‘after‘ => ‘‘, ) ); $range = intval( $s[‘range‘] ); global $paged, $wp_query; if ( ! $max_page ) { $max_page = $wp_query->max_num_pages; } if( $max_page > 1 ) { echo $s[‘before‘]; echo ‘<ul class="pagination">‘; echo ‘‘; if( ! $paged ) { $paged = 1; } if( $paged != 1 ) { echo ‘<li><a href="‘ . get_pagenum_link(1) . ‘" class="extend first"> ? </a></li>‘; } // echo ‘<li>‘; // previous_posts_link( ‘ ? ‘ ); // echo ‘</li>‘; if( $max_page > $range ) { if( $paged < $range ) { for( $i = 1; $i <= ( $range + 1 ); $i++ ) { $classes = array( ‘page‘ ); $href = get_pagenum_link($i); if( $i == $paged ) $classes[] = ‘active‘; printf( ‘<li><a href="%s" class="%s">%s</a></li>‘, $href, implode( ‘ ‘, $classes ), $i ); } echo ‘<li class="disable"><a href="javascript:;">...</a></li>‘; } elseif( $paged >= ( $max_page - ceil( ( $range/2 ) ) ) ) { echo ‘<li class="disable"><a href="javascript:;">...</a></li>‘; for( $i = $max_page - $range; $i <= $max_page; $i++ ) { $classes = array( ‘page‘ ); $href = get_pagenum_link($i); if( $i == $paged ) $classes[] = ‘active‘; printf( ‘<li><a href="%s" class="%s">%s</a></li>‘, $href, implode( ‘ ‘, $classes ), $i ); } } elseif( $paged >= $range && $paged < ( $max_page - ceil( ( $range/2 ) ) ) ) { echo ‘<li class="disable"><a href="javascript:;">...</a></li>‘; for( $i = ( $paged - ceil( $range/2 ) ); $i <= ( $paged + ceil( ( $range/2 ) ) ); $i++ ) { $classes = array( ‘page‘ ); $href = get_pagenum_link($i); if( $i == $paged ) $classes[] = ‘active‘; printf( ‘<li><a href="%s" class="%s">%s</a></li>‘, $href, implode( ‘ ‘, $classes ), $i ); } echo ‘<li class="disable"><a href="javascript:;">...</a></li>‘; } } else { for( $i = 1; $i <= $max_page; $i++ ) { $classes = array( ‘page‘ ); $href = get_pagenum_link($i); if( $i == $paged ) $classes[] = ‘active‘; printf( ‘<li><a href="%s" class="%s">%s</a></li>‘, $href, implode( ‘ ‘, $classes ), $i ); } } // echo ‘<li>‘; // next_posts_link(‘ ? ‘); // echo ‘</li>‘; if( $paged != $max_page ) { echo ‘<li><a href="‘ . get_pagenum_link($max_page) . ‘" class="extend last"> ? </a></li>‘; } echo ‘</ul><!-- .wp-pagenavi -->‘; echo $s[‘after‘]; } } function of_previous_posts_link_attributes() { return ‘class="previouspostslink"‘; } add_filter( ‘previous_posts_link_attributes‘, ‘of_previous_posts_link_attributes‘ ); function of_next_posts_link_attributes() { return ‘class="nextpostslink"‘; } add_filter( ‘next_posts_link_attributes‘, ‘of_next_posts_link_attributes‘ );
6.手机端访问跳转
$agent = $_SERVER[‘HTTP_USER_AGENT‘]; if(strpos($agent,"comFront") || strpos($agent,"iPhone") || strpos($agent,"MIDP-2.0") || strpos($agent,"Opera Mini") || strpos($agent,"UCWEB") || strpos($agent,"Android") || strpos($agent,"Windows CE") || strpos($agent,"SymbianOS")) header("Location:http://likinming.com/m/"); exit;/*(使用 header(location) 就跳转到另一个页面了,但事实上,PHP却仍然会执行后台的代码的)
7.ip
function ip() { if(getenv(‘HTTP_CLIENT_IP‘) && strcasecmp(getenv(‘HTTP_CLIENT_IP‘), ‘unknown‘)) { $ip = getenv(‘HTTP_CLIENT_IP‘); } elseif(getenv(‘HTTP_X_FORWARDED_FOR‘) && strcasecmp(getenv(‘HTTP_X_FORWARDED_FOR‘), ‘unknown‘)) { $ip = getenv(‘HTTP_X_FORWARDED_FOR‘); } elseif(getenv(‘REMOTE_ADDR‘) && strcasecmp(getenv(‘REMOTE_ADDR‘), ‘unknown‘)) { $ip = getenv(‘REMOTE_ADDR‘); } elseif(isset($_SERVER[‘REMOTE_ADDR‘]) && $_SERVER[‘REMOTE_ADDR‘] && strcasecmp($_SERVER[‘REMOTE_ADDR‘], ‘unknown‘)) { $ip = $_SERVER[‘REMOTE_ADDR‘]; } return preg_match("/[\d\.]{7,15}/", $ip, $matches) ? $matches[0] : ‘unknown‘; }
时间: 2024-10-15 10:38:50