修改默认文章每页显示新闻数目(加入到functions.php中)
$option_posts_per_page = get_option( 'posts_per_page' ); add_action( 'init', 'my_modify_posts_per_page', 0); function my_modify_posts_per_page() { add_filter( 'option_posts_per_page', 'my_option_posts_per_page' ); } function my_option_posts_per_page( $value ) { global $option_posts_per_page; if ( is_tax( 'portfolio-category') ) { return 2; } else { return $option_posts_per_page; }}
在后台列表页面添加新的栏目
这里主要是改变WP_List_Table,但由于Wordpress提供有现成的Filter API,故直接利用Filter即可,如果想通过WP_List_Table去改变,参见:http://wpengineer.com/2426/wp_list_table-a-step-by-step-guide/
主要用到的Filter有:
(1) manage_posts_columns这个主要是用在文章列表页的栏目管理,包括除pages外的所有类型post的列表页面。管理pages的要用mange_pages_columns
(2) manage_${post_type}_posts_columns相对于上一个就更细致一些,它主要用来修改指定自定义类型的列表页栏目的管理,这个通常结合manage_posts_custom_column(用于设置自定义栏目的值)。管理pages的自定义栏目的值要用manage_pages_custom_column。
//管理后台列表页面的栏目
function jl_add_location_columns($columns) { unset($columns['comments']); return array_merge($columns, array('shop_location' => '位置')); } add_filter('manage_post_posts_columns' , 'jl_add_location_columns'); add_action( 'manage_posts_custom_column' , 'jl_custom_columns', 10, 2 ); function jl_custom_columns( $column, $post_id ) { switch ( $column ) { case 'shop_location' : echo get_post_meta( $post_id , 'shop_location' , true ); break; } }
现在wordpress中直接可以上传tudou、youku和56com的视频网址到文章内容里面,然后就可以直接播放了。
这一次讲wordpress的contact form 7插件的设置,这个插件对于一些“招商加盟,联系我们”等页面
特别方便好用,其设置也很简单,但要知道几点
(1)每个input要按照里面的设置去生成标签,
(2)下面的邮箱要填写,否这会出现“你的留言发送失败。请稍后再尝试发送或者使用其他方法联系
管理员。”的错误
(3)在额外的设置中可以贴一些操作,如:“on_sent_ok: "location='留言成功后要跳转的页面';"
,这个可以避免重复提交,提交成功后页面就会跳转到你设置的页面。
另外可以集成里面自带的form效果,此时只需要在页面中加载”style.css、jquery.form.min.js和
script.js即可。
关于Easy WP SMTP的设置:
设置126邮箱
如下图
三、下面说下wordpress中怎么实现简单的购物车功能
Wordpress提供多用户功能,而且里面还提供了五中角色,分别是administrator、editor、author、subscriber和contributer。
对于购物车,一般用户只需要看到他提交的信息就好,并不需要去修改,所以这里选择将用户都
设置为subscriber,只能在后台查看到“文章”,之所以不选择author角色是因为这个角色会使得客户具有编辑“文章”的功能,这是不合适的。这还不够,因为其他板块的内容也能让客户看到,所以要其他版块的内容通过下图中代码去掉:
//设置编辑角色显示的自定义分类 function get_user_role() { global $current_user; $user_roles = $current_user->roles; $user_role = array_shift($user_roles); return $user_role; } if (( is_user_logged_in()) && (get_user_role()=='contributor')) { function removeMenu(){ global $menu; // ****************** Find the numbers corresponding to the menu items to remove in wp-admin/menu.php ********** unset($menu[5]); // remove post menu unset($menu[6]); unset($menu[7]); unset($menu[8]); unset($menu[9]); unset($menu[10]); unset($menu[11]); unset($menu[12]); unset($menu[13]); unset($menu[14]); unset($menu[16]); unset($menu[17]); unset($menu[20]); unset($menu[25]); // remove comments menu unset($menu[26]); unset($menu[75]); // remove tools menu } add_action( 'admin_head' , 'removeMenu'); function menu_redirect() { // Redirect links. Thanks to Vladimir Garagulya at http://www.shinephp.com/how-to-block-wordpress-admin-menu-item/ // Although menu items have been removed a user could still paste in the url for that menu item and go to that page. This redirects such urls back to the dashboard. // Before removing the menu items click on each one and copy the relevant urls. Take the last bit of each url and paste into either $linksToAllow = array // or $linksToBlock = array (below) // Again, before removing the menu items, check that the above code works when you click on each menu item. // edit.php is not redirected for some reason. // If the user pastes edit.php onto the end of /wp-admin/ they can see a list of all the posts that have been published. // However, they can't do anything with that list of posts. And trying to add a new post redirects them back to the dashboard. // It's not ideal. Redirecting edit.php back to the dashboard would be better. $result = false; $linksToAllow = array('edit.php?post_type=review', 'post-new.php?post_type=review'); // Links to allow foreach ($linksToAllow as $key=>$value) { $result = stripos($_SERVER['REQUEST_URI'], $value); if ($result!==false) { $result = 'blah'; break; } } if ($result!=='blah') { $linksToBlock = array('edit.php', 'post-new.php', 'tools.php', 'profile.php', 'edit-comments.php'); // Links to block (i.e. to redirect back to wp-admin/index.php) foreach ($linksToBlock as $key=>$value) { $result = stripos($_SERVER['REQUEST_URI'], $value); if ($result!==false) { $result = 'something'; break; } } } if ($result=='something') { wp_redirect(get_option('siteurl') . '/wp-admin/index.php'); } } add_action('admin_menu', 'menu_redirect'); }
设置了这个之后,就可以让客户在后台只看到特定内容了。
四、修复wordpress的lot主题的image插件的图片路径问题
//同步自定义repeater imagebox图片路径 function manipulate_cfi_row($fields) { // whatever you want to do here: foreach($fields as &$field){ $field['goods_slide_images']['src'] = str_replace('test4.wlst.cn', 'www.jinlinghomedeco.com', $field['goods_slide_images']['src']); } return $fields; } function manipulate_cfi_data() { global $wpdb; $data = $wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = 'goods_rep_'"); foreach ( $data as $row ) { $old_str = str_replace('www.jinlinghomedeco.com', 'test4.wlst.cn', $row->meta_value); if(unserialize($old_str) === FALSE){ continue; } $new_data = manipulate_cfi_row(unserialize($old_str)); update_post_meta($row->post_id, 'goods_rep_', $new_data); } } //同步自定义分类meta图片路径 function manipulate_cfi_row($fields) { // whatever you want to do here: $fields['cat_image']['src'] = str_replace('test4.wlst.cn', 'www.jinlinghomedeco.com', $fields['cat_image']['src']); return $fields; } function manipulate_cfi_data() { global $wpdb; $categories = get_categories(array( 'child_of' => 2, 'hide_empty' => 0, 'orderby' => 'id' )); foreach($categories as $category){ $data = $wpdb->get_results("SELECT option_id, option_value FROM $wpdb->options WHERE option_name = 'tax_meta_".$category->cat_ID."'"); foreach ( $data as $row ) { $old_str = str_replace('www.jinlinghomedeco.com', 'test4.wlst.cn', $row->option_value); if(unserialize($old_str) === FALSE){ continue; } $new_data = manipulate_cfi_row(unserialize($old_str)); update_tax_meta($category->cat_ID, 'cat_image', $new_data['cat_image']); } } }