C#:自动更新Smarthosts到本地hosts
SmartHosts 是一个托管在 googlecode 上的项目,定期更新 hosts 文件,你懂的。为了方便自动更新,不用每次都打开网站,于是尝试用 c# 实现了一下。
实现原理
从 https://smarthosts.googlecode.com/svn/trunk/hosts 抓取数据,写入本地 hosts。
实现步骤
1.抓取数据
2.判断本地是否有 hosts 文件。没有则直接建立,并写入抓取下来的数据;有则读取
SmartHosts 是一个托管在 googlecode 上的项目,定期更新 hosts 文件,你懂的。为了方便自动更新,不用每次都打开网站,于是尝试用 c# 实现了一下。
实现原理
从 https://smarthosts.googlecode.com/svn/trunk/hosts 抓取数据,写入本地 hosts。
实现步骤
1.抓取数据
2.判断本地是否有 hosts 文件。没有则直接建立,并写入抓取下来的数据;有则读取
基本规则:
扩展必须有 config.xml
文件;
扩展必须有一个在后台执行操作的文件(通常是一个 index.html
文件);
注入脚本必须放到 includes
文件夹下;
所有文件必须打包进一个 zip 压缩包中,并将压缩包后缀名更改为 .oex
获取分类数据
根据文章ID获取文章分类数据:get_the_category()
根据分类别名获取分类数据:get_category_by_slug()
<?php $cat = get_the_category($post_id);//返回数组,参数默认为当前文章ID ?>
<?php $cat = get_category_by_slug($slug);//返回数组?>
根据分类ID或分类对象获取分类数据:get_category()
<?php $cat = get_category( $category,$output,$filter);?>
<?php
$cat = get_category_by_slug($slug);//返回数组?>
<?php
$cat_id = $cat->term_id;//获取分类ID
$cat_count = $cat->count;//获取分类文章数
$cat_description = $cat->description;//获取分类描述
$cat_slug = $cat->slug;//获取分类别名
$cat_parent = $cat->parent;//获取分类父级引用
?>
get_posts()
用于在 WordPress 中提取多篇文章。
调用
<?php $posts = get_posts($args); ?>
参数
<?php
$args = array(
'numberposts' => 5,
'offset' => 0,
'category' => ,
'orderby' => 'post_date',
'order' => 'DESC',
'include' => ,
'exclude' => ,
'meta_key' => ,
'meta_value' => ,
'post_type' => 'post',
'post_mime_type' => ,
'post_parent' => ,
'post_status' => 'publish' );
?>
调用
在需要调用导航菜单的地方插入<?php wp_nav_menu($args);>
wp_nav_menu($args)
函数中,参数$args
的默认值
<?php $defaults = array(
'theme_location' => ,
'menu' => ,
'container' => 'div',
'container_class' => 'menu-{menu slug}-container',
'container_id' => ,
'menu_class' => 'menu',
'menu_id' => ,
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => ,
'after' => ,
'link_before' => ,
'link_after' => ,
'items_wrap' => '<ul id=”%1$s” class=”%2$s”>%3$s</ul>',
'depth' => 0,
'walker' => );
?>
在 wp-config.php
文件里添加以下两句:)
define('WP_POST_REVISIONS',false);
define('AUTOSAVE_INTERVAL',false);
WP_POST_REVISIONS是设置是否保存修订版本,设为true,就表示每修改一次文章就会在数据库新保存一条数据;
AUTOSAVE_INTERVAL是设置自动保存文章时间,单位为秒,就表示当编辑文章时每间隔3600秒自动在数据库新保存一条数据。
另外,将 wp-admin\post-new.php
和 wp-admin\post.php
里的 wp_enqueue_script('autosave')
注释掉,但是这样在新建文章未保存前不会自动生成固定链接。