问题描述
我正在尝试从 wordpress 的自定义帖子(产品)标题自动生成标签,因此我可以使用这些标签而不是 Jetpack 的共享消息。我希望完成的是一个分享信息,例如“#tag #tag #tag URL”(理想情况下),或者如果第一个太复杂或不可能的话,至少是“标题 URL”。
我的产品帖子是自动创建的,然后立即由 Jetpack 作为 Facebook 的摘录+URL 共享。我试图在代码片段中使用下面的代码,但它破坏了产品页面并且也没有完成它的工作。我还应该提到,这些都不是我的创作,我正在试验 PHP,并且我结合了来自不同文章的 2-3 部分代码。
if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'publicize' ) ) {
function title_as_keywords( $word )
{
$blacklist = array('about','above','across','after','afterwards','again','against','almost','alone','along','already','also','although','always','among','amongst','amoungst','amount','another','anyhow','anyone','anything','anyway','anywhere','around','back','became','because','become','becomes','becoming','been','before','beforehand','behind','being','below','beside','besides','between','beyond','bill','both','bottom','call','cannot','cant','computer','Could','Couldnt','describe','detail','done','down','dropshipping','dropship','during','each','eight','either','eleven','else','elsewhere','empty','enough','even','ever','every','everyone','everything','everywhere','except','free','fifteen','fify','fill','find','fire','first','five','former','formerly','forty','found','four','from','front','full','further','give','hasnt','have','hence','here','hereafter','hereby','herein','hereupon','hers','herse','himse','however','hundred','indeed','interest','into','itse','keep','last','latter','latterly','least','less','made','many','meanwhile','might','mill','mine','more','moreover','most','mostly','move','much','must','myse','name','namely','neither','never','nevertheless','next','nine','nobody','none','noone','nothing','Nowhere','often','once','only','onto','original','other','others','otherwise','ours','ourselves','over','part','perhaps','please','rather','same','seem','seemed','seeming','seems','serIoUs','several','should','show','side','since','sincere','sixty','some','somehow','someone','something','sometime','sometimes','somewhere','still','such','system','take','than','that','their','them','themselves','then','thence','there','thereafter','thereby','therefore','therein','thereupon','these','they','thick','thin','third','this','those','though','three','through','throughout','thru','thus','together','toward','towards','twelve','twenty','under','until','upon','very','well','were','what','whatever','website','when','whence','whenever','where','whereafter','whereas','whereby','wherein','whereupon','wherever','whether','which','while','whither','whoever','whole','whom','whose','will','with','within','without','would','your','yours','yourself','yourselves','sale','Whosale&Dropship','Whosale'
);
$whitelist = array('lg','3D','in','mp3','mp4','360','1st','2nd','3rd','ios','ssd','hdd','usb','sd','gsm','gps','tv','pc','tf','vr','pro','max','64','32','bit','hd','car','dog','cat','pet','ghz','aux','pen','4.0','5.0','3.0','2.0','key','10w','5w','15w','20w','led','low','ps4','ps3','ps2','one','two','six','ten','mic','hub','wii','18w','lcd','dvd','map','fm','am','sos','obd','kit','kid','for'); // Whitelisted words ...
if ( (!in_array( $word,$blacklist ) && strlen( $word ) > 3 ) || in_array($word,$whitelist)) {
$word_with_comma = '#' .$word. ' ';
return $word_with_comma;
}
else { return ''; }
}
function tsj_publicize_hashtags() {
$post = get_post();
if ( ! empty( $post ) ) {
$title = get_post_field( 'post_title',$post->ID );
$parts = explode( ' ',strtolower($title) );
$str = '';
foreach (array_unique($parts) as $word) {
$str.= title_as_keywords($word);
}
$str = mb_substr($str,-1);
update_post_Meta( $post->ID,'_wpas_mess',$str );
}
}
function tsj_cust_pub_message_save() {
add_action( 'save_post','tsj_publicize_hashtags',21 );
}
add_action( 'publish_post','tsj_cust_pub_message_save' );
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)