技术文章:PHP程序开发超级外链工具源码 站长SEO工具/一键批量外链源码
优采云 发布时间: 2022-10-25 01:26技术文章:PHP程序开发超级外链工具源码 站长SEO工具/一键批量外链源码
PHP程序开发超级外链工具源码,站长SEO工具,一键批量外链源码。超级外链工具源码,HTML+php+LayUI框架,部分JS加密,无背景,外链界面保存文字。附带 9602 高级链接。
恭喜,此资源免费,请先登录
开放会员无限制下载所有资源。VIP扫码开通包月会员只需29元,季会员69元,年会119元(1元=1屏聚币)。如果您在充值升级过程中遇到任何问题,请及时发邮件联系我们
技巧:WordPress——免插件自动为文章添加设置特*敏*感*词*像的三种方法
wordpress 特*敏*感*词*片可以为每个文章设置一个缩略图,但是必须手动设置。下面我们使用代码自动将文章中的第一张图片添加为缩略图,如果文章中没有图片,我们可以调用媒体库中的一张图片作为文章的缩略图>,或者我们可以设置一个文件夹来上传我们需要设置为缩略图的图片。
在当前主题的functions.php中加入如下代码
function wpforce_featured() {
global $post;
$already_has_thumb = has_post_thumbnail($post->ID);
if (!$already_has_thumb) {
$attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
if ($attached_image) {
foreach ($attached_image as $attachment_id => $attachment) {
set_post_thumbnail($post->ID, $attachment_id);
}
}
}
} //end function
add_action('the_post', 'wpforce_featured');
add_action('save_post', 'wpforce_featured');
add_action('draft_to_publish', 'wpforce_featured');
add_action('new_to_publish', 'wpforce_featured');
add_action('pending_to_publish', 'wpforce_featured');
add_action('future_to_publish', 'wpforce_featured');
这里有一段有用的代码,自动将文章中的第一张图片设置为特*敏*感*词*片,如果你手动设置了特*敏*感*词*片,你可以覆盖这段代码,这样即使忘记设置,wp也会自动调用文章 中的第一张图片作为缩略图。
自动将媒体库中的图像调用为缩略图
问题是,如果我们的 文章 中没有图片而忘记设置特*敏*感*词*片,那么我们可以让 WP 调用媒体库中的指定图片作为缩略图。
function wpforce_featured() {
global $post;
$already_has_thumb = has_post_thumbnail($post->ID);
if (!$already_has_thumb) {
$attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
if ($attached_image) {
foreach ($attached_image as $attachment_id => $attachment) {
set_post_thumbnail($post->ID, $attachment_id);
}
<p>
} else {
set_post_thumbnail($post->ID, '66');
}
}
} //end function
add_action('the_post', 'wpforce_featured');
add_action('save_post', 'wpforce_featured');
add_action('draft_to_publish', 'wpforce_featured');
add_action('new_to_publish', 'wpforce_featured');
add_action('pending_to_publish', 'wpforce_featured');
add_action('future_to_publish', 'wpforce_featured');</p>
其中$post->ID,'66'是媒体库中图片的id
如何查看媒体库中图片的ID?
WP-background-multimedia-media库,使用列表浏览方式,鼠标指向图片,图片的ID会显示在浏览器下方,也可以阅读下面的文章来实现:
wordpress 后台没有显示 文章 和类别 ID 的插件
自定义图像作为特*敏*感*词*像
/**
* 添加特色缩略图支持相关文章带有缩略图
*/
if ( function_exists('add_theme_support') )add_theme_support('post-thumbnails');
//让你的主题开启特*敏*感*词*像功能
function post_thumbnail_src(){
global $post;
if( $values = get_post_custom_values("thumb") ) {//输出自定义域图片地址
$values = get_post_custom_values("thumb");
$post_thumbnail_src = $values [0];
} elseif( has_post_thumbnail() ){//如果有特色缩略图,则输出缩略图地址
$thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'thumbnail');
//其中full可以修改的,可以为thumbnail, medium, large or full(分别代表最小的缩略图、中等、大和原始尺寸)
$post_thumbnail_src = $thumbnail_src [0];
} else {
$post_thumbnail_src = '';
ob_start();
<p>
ob_end_clean();
$output = preg_match_all('//i', $post->post_content, $matches);
$post_thumbnail_src = $matches [1] [0]; //获取该图片 src
if(empty($post_thumbnail_src)){ //如果日志中没有图片,则显示随机图片
$random = mt_rand(1, 10);
echo get_bloginfo('template_url');
echo '/images/pic/'.$random.'.jpg';
//如果日志中没有图片,则显示默认图片
//echo '/images/default_thumb.jpg';
}
};
echo $post_thumbnail_src;
}</p>
我们在主题下创建图片文件夹/images/pic/,将你最先展示的图片上传为随机调用,/images/default_thumb.jpg是最默认调用。当然,我们可以选择这两个功能之一。一个被注释掉了。
PS:调用特*敏*感*词*片并设置大小
要使您的主题支持特*敏*感*词*像,您必须将以下代码添加到 functions.php:
if ( function_exists('add_theme_support') )add_theme_support('post-thumbnails');
在帖子模板调用中:
可以调用不同大小的图像:
the_post_thumbnail(); // 无参数,默认调用Thumbnail
the_post_thumbnail('thumbnail');// Thumbnail(默认尺寸 150px150px max)
the_post_thumbnail('medium'); // Medium resolution(default300px300px max)
the_post_thumbnail('large'); // Large resolution(default640px640px max)
the_post_thumbnail('full'); // Full resolution(original size uploaded)
the_post_thumbnail( array(100,100) );//Other resolutions
总结
1、如果自己制作主题,可以在调试的时候尝试自己喜欢的方法。
2. 很多文章已经在你的网站上发布,并且启用了特*敏*感*词*片。谨慎使用它们。可能你选择的某个代码功能会影响你发布的文章,无法正常显示!
3. 精选图片会占用大量服务器空间,因为每张图片都会被裁剪成多个不同大小的缩略图,方便不同位置调用。最重要的是不支持外部链接。