需要达到的目的:将文章内容里面的下载地址全部转移到插件ordown里面以方便管理,由于数据量比较大,自然有涉及到数据库操作。上图是WordPress插件ordown在文章发布时的设置参数,我需要将每一篇内容都设置上述三个地方。
这三个地方涉及到数据库的上面几条数据库记录的添加,达到每个有下载链接的文章的post_id有与之对应的的meta_key和meta_value的相应记录,以下代码所示:
meta_key=ordown_official and meta_value=yes(启用官方下载) meta_key=ordown_downname1 and meta_value="本地下载"(自定义网盘1设置为“本地下载”) meta_key=ordown_downurl4 and meta_value="真实下载地址"(下载地址1设置为真实下载地址)
将原站点有下载链接的内容分别添加以上三条记录以后,前台就会显示一个ordown的下载框,这就是我们要达到的效果:
首先,添加这三条记录是在wp_postmeta里面。meta_id是主键,自动加1,不用管它,设置为null即可,下面sql代码可直接在phpMyAdmin后台进行执行;
以下代码,term_taxonomy_id = 4这个是分类目录的id,
1、开启官方下载;
INSERT INTO wp_postmeta(meta_id, post_id, meta_key, meta_value) select null,id,'ordown_official','yes' 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 = 4 and taxonomy = "category"
2、加入本地下载;
INSERT INTO wp_postmeta(meta_id, post_id, meta_key, meta_value) select null,id,'ordown_downname1','本地下载' 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 = 4 and taxonomy = "category"
3、将每篇内容的下载链接插入到 meta_value="真实下载地址"这个里面。
因为真实下载链接处于这段代码中的https://www.pinzixing.com/d/D44Caps-Bold.rar
<p class="downss"><a class="download" href="https://www.pinzixing.com/d/D44Caps-Bold.rar" target="_blank" rel="noopener noreferrer">本地下载</a></p>
所以我们要用到以下sql代码来截取href="和" target="字符串中间的字符,看不明白的可以参考SQL用substr和instr函数截取特定字符之间的字符。
INSERT INTO wp_postmeta(meta_id, post_id, meta_key, meta_value) select null,id,'ordown_downurl4','substr(post_content,instr(post_content,'href="')+6,instr(post_content,'" target="')-(instr(post_content,'href="')+6))' 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 = 4 and taxonomy = "category"
以上三段sql命令必须都执行,否则前端不显示下载!
评论