php下载远程图片保存到本地并替换文章的中的内容
- 以前的文章
- 2018-04-08
- 12热度
- 0评论
需要手动创建目录Uploads
需要传入的参数$body 嗯,HTML代码
$url 传入一个源网站的地址,我没写检测功能,这个会手动检查时http还是https协议
<?php
include ( "wp-config.php" ) ;
require_once (ABSPATH.'wp-blog-header.php');
global $wpdb;
$CID = 2;//分类id,只支持一个分类
$sql="SELECT ID,post_title,post_content FROM wp_posts,wp_term_relationships,wp_term_taxonomy WHERE ID=object_id and wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id and post_type='post' and post_status = 'publish' and wp_term_relationships.term_taxonomy_id = $CID and taxonomy = 'category' order by ID desc";
$myrows = $wpdb->get_results($sql);
add_action('save_post', 'auto_add_tags');
foreach ($myrows as $data) {
echo $data->ID."<br />";//这是文章ID
echo $data->post_title."<br />";//这是文章标题
//echo $b->post_content."<br />";//这是文章内容
$tags = get_tags( array('hide_empty' => false) );
$post_id = $data->ID;
$post_content = get_post($data->ID)->post_content;
if ($tags) {
$i = 0;
$arrs = object2array($tags);
shuffle($arrs);
$tags = array2object($arrs);
// 打乱顺序
foreach ( $tags as $tag ) {
// 如果文章内容出现了已使用过的标签,自动添加这些标签
if ( strpos($post_content, $tag->name) !== false){
if ($i == 15) {
// 控制输出数量
break;
}
wp_set_post_tags( $post_id, $tag->name, true );
$i++;
}
}
}
}
?>
