圖片信息實(shí)際仍存儲(chǔ)在posts表中,post_type為attachment
創(chuàng)新互聯(lián)于2013年創(chuàng)立,先為晉州等服務(wù)建站,晉州等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為晉州企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
后臺(tái)相冊(cè)編輯界面里沒有專門的欄目用于填寫外鏈地址,不過可以通過其他字段實(shí)現(xiàn)啊
如下圖,在alt text字段里填上該圖片的外鏈
接著,需要參考wp-includes/media.php文件里的gallery_shortcode函數(shù)來(lái)重構(gòu)gallery的輸出
在functions.php中添加代碼如下:
add_filter('post_gallery',?'my_post_gallery',?10,?3);
function?my_post_gallery(?$html?=?'',?$attr,?$instance?)?{
$post?=?get_post();
$html5?=?current_theme_supports(?'html5',?'gallery'?);
$atts?=?shortcode_atts(?array(
'order'??????=?'ASC',
'orderby'????=?'menu_order?ID',
'id'?????????=?$post???$post-ID?:?0,
'itemtag'????=?$html5???'figure'?????:?'dl',
'icontag'????=?$html5???'div'????????:?'dt',
'captiontag'?=?$html5???'figcaption'?:?'dd',
'columns'????=?3,
'size'???????=?'thumbnail',
'include'????=?'',
'exclude'????=?'',
'link'???????=?'none'
),?$attr,?'gallery'?);
$id?=?intval(?$atts['id']?);
if?(?!?empty(?$atts['include']?)?)?{
$_attachments?=?get_posts(?array(?'include'?=?$atts['include'],?'post_status'?=?'inherit',?'post_type'?=?'attachment',?'post_mime_type'?=?'image',?'order'?=?$atts['order'],?'orderby'?=?$atts['orderby']?)?);
$attachments?=?array();
foreach?(?$_attachments?as?$key?=?$val?)?{
$attachments[$val-ID]?=?$_attachments[$key];
}
}?elseif?(?!?empty(?$atts['exclude']?)?)?{
$attachments?=?get_children(?array(?'post_parent'?=?$id,?'exclude'?=?$atts['exclude'],?'post_status'?=?'inherit',?'post_type'?=?'attachment',?'post_mime_type'?=?'image',?'order'?=?$atts['order'],?'orderby'?=?$atts['orderby']?)?);
}?else?{
$attachments?=?get_children(?array(?'post_parent'?=?$id,?'post_status'?=?'inherit',?'post_type'?=?'attachment',?'post_mime_type'?=?'image',?'order'?=?$atts['order'],?'orderby'?=?$atts['orderby']?)?);
}
if?(?empty(?$attachments?)?)?{
return?'';
}
if?(?is_feed()?)?{
$output?=?"\n";
foreach?(?$attachments?as?$att_id?=?$attachment?)?{
$output?.=?wp_get_attachment_link(?$att_id,?$atts['size'],?true?)?.?"\n";
}
return?$output;
}
$itemtag?=?tag_escape(?$atts['itemtag']?);
$captiontag?=?tag_escape(?$atts['captiontag']?);
$icontag?=?tag_escape(?$atts['icontag']?);
$valid_tags?=?wp_kses_allowed_html(?'post'?);
if?(?!?isset(?$valid_tags[?$itemtag?]?)?)?{
$itemtag?=?'dl';
}
if?(?!?isset(?$valid_tags[?$captiontag?]?)?)?{
$captiontag?=?'dd';
}
if?(?!?isset(?$valid_tags[?$icontag?]?)?)?{
$icontag?=?'dt';
}
$columns?=?intval(?$atts['columns']?);
$itemwidth?=?$columns??0???floor(100/$columns)?:?100;
$float?=?is_rtl()???'right'?:?'left';
$selector?=?"gallery-{$instance}";
$gallery_style?=?'';
/**
*?Filters?whether?to?print?default?gallery?styles.
*
*?@since?3.1.0
*
*?@param?bool?$print?Whether?to?print?default?gallery?styles.
*????????????????????Defaults?to?false?if?the?theme?supports?HTML5?galleries.
*????????????????????Otherwise,?defaults?to?true.
*/
if?(?apply_filters(?'use_default_gallery_style',?!?$html5?)?)?{
$gallery_style?=?"
style?type='text/css'
#{$selector}?{
margin:?auto;
}
#{$selector}?.gallery-item?{
float:?{$float};
margin-top:?10px;
text-align:?center;
width:?{$itemwidth}%;
}
#{$selector}?img?{
border:?2px?solid?#cfcfcf;
}
#{$selector}?.gallery-caption?{
margin-left:?0;
}
/*?see?gallery_shortcode()?in?wp-includes/media.php?*/
/style\n\t\t";
}
$size_class?=?sanitize_html_class(?$atts['size']?);
$gallery_div?=?"div?id='$selector'?class='gallery?galleryid-{$id}?gallery-columns-{$columns}?gallery-size-{$size_class}'";
/**
*?Filters?the?default?gallery?shortcode?CSS?styles.
*
*?@since?2.5.0
*
*?@param?string?$gallery_style?Default?CSS?styles?and?opening?HTML?div?container
*??????????????????????????????for?the?gallery?shortcode?output.
*/
$output?=?apply_filters(?'gallery_style',?$gallery_style?.?$gallery_div?);
$i?=?0;
foreach?(?$attachments?as?$id?=?$attachment?)?{
$attr?=?(?trim(?$attachment-post_excerpt?)?)???array(?'aria-describedby'?=?"$selector-$id"?)?:?'';
if?(?!?empty(?$atts['link']?)??'file'?===?$atts['link']?)?{
$image_output?=?wp_get_attachment_link(?$id,?$atts['size'],?false,?false,?false,?$attr?);
}?elseif?(?!?empty(?$atts['link']?)??'none'?===?$atts['link']?)?{
$attr['alt']?=?get_the_title($post-ID);
$image_output?=?wp_get_attachment_image(?$id,?$atts['size'],?false,?$attr?);
$custom_link?=?trim(?strip_tags(?get_post_meta(?$id,?'_wp_attachment_image_alt',?true?)?)?);
$image_output?=?sprintf(?'a?href="%s"?title="%s"%sa',
$custom_link,
$attr['alt'],
$image_output
);
}?else?{
$image_output?=?wp_get_attachment_link(?$id,?$atts['size'],?true,?false,?false,?$attr?);
}
$image_meta??=?wp_get_attachment_metadata(?$id?);
$orientation?=?'';
if?(?isset(?$image_meta['height'],?$image_meta['width']?)?)?{
$orientation?=?(?$image_meta['height']??$image_meta['width']?)???'portrait'?:?'landscape';
}
$output?.=?"{$itemtag}?class='gallery-item'";
$output?.=?"
{$icontag}?class='gallery-icon?{$orientation}'
$image_output
/{$icontag}";
if?(?$captiontag??trim($attachment-post_excerpt)?)?{
$output?.=?"
{$captiontag}?class='wp-caption-text?gallery-caption'?id='$selector-$id'
"?.?wptexturize($attachment-post_excerpt)?.?"
/{$captiontag}";
}
$output?.=?"/{$itemtag}";
if?(?!?$html5??$columns??0??++$i?%?$columns?==?0?)?{
$output?.=?'br?style="clear:?both"?/';
}
}
if?(?!?$html5??$columns??0??$i?%?$columns?!==?0?)?{
$output?.=?"
br?style='clear:?both'?/";
}
$output?.=?"
/div\n";
return?$output;????
}
最后的效果:
//去除默認(rèn)的相冊(cè)短
remove_shortcode(‘gallery’, ’gallery_shortcode’);
//添加相冊(cè)的短代碼
function itluren_gallery_shortcode(){
global $post ;
if (preg_match_all(‘/\[ga llery([\r\n]*?)ids= “([\s\S]*?)” \]/i’, $post -post_content, $matches )){
$pictures_ids = $matches [2][0];
$pictures_array = explode (‘,’, $pictures_ids );
$all_images_count_num = count ( $pictures_array );
$post_permalink_str =get_permalink( $post -ID);
$options = get_option(‘itluren’);
$post_title_str = $post -post_title;
$baidu_share_sina = $options ['mts_baidu_share_sina'];
$baidu_share_qq = $options ['mts_baidu_share_qq'];
if ( $post_permalink_str != ” ){
$post_permalink_str_u =urlencode( $post_permalink_str );
}
if ( $post -post_title=! ” ){
$post_title_str_u =urlencode( $post -post_title);
}
for ( $i =0; $i count ( $pictures_array ); $i ++){
$picture_number = $i +1;
$image_information =wp_get_attachment_image_src( $pictures_array [ $i ]);
$image_altstr =get_post_meta((int) $pictures_array [ $i ],’_wp_attachment_image_alt’,true);
$image_data =itluren_get_attachment((int) $pictures_array [ $i ]);
$image_caption = $image_data ['caption'];
$image_des = $image_data ['description'];
$image_title = $image_data ['title'];
if ( $image_altstr == ” ){
if ( $image_des != ” ){
$image_altstr = $image_des ;
} else {
$image_altstr =’《’. $post_title_str .’》第’. $picture_number .’張’;
}
}
if ( $image_altstr != ” ){
$image_alt_str_u =urlencode( $image_altstr );
}
$image_url_str_u =urlencode( $image_information [0]);
if ( $image_caption != ” ){
$image_desc = $image_caption ;
} else if ( $image_des != ” ){
$image_desc = $image_des ;
} else {
$image_desc =’暫無(wú)說明或者描述’;
}
if ( $image_title != ” ){
$image_a_title = $image_title ;
} else {
$image_a_title =’《’. $post_title_str .’》第’. $picture_number .’張’;
}
用一下幾個(gè)插件就可以了
1.Coppermine相冊(cè)
簡(jiǎn)介:Coppermine Gallery本身是個(gè)簡(jiǎn)便易用的php相冊(cè),而后推出的psnGallery插件使得WordPress用戶可以很方便地在blog里面插入圖片。
好處:psnGallery的功能非常強(qiáng)大,是圖片blog用戶的首選。
缺陷:Coppermine Gallery缺省安裝的界面非常復(fù)雜。
2.Menalto Gallery相冊(cè)
簡(jiǎn)介:這個(gè)相冊(cè)可能是最受歡迎的網(wǎng)站相冊(cè)軟件了,非常容易安裝,而且支持自定義的html鑲嵌方式(通過修改html_wrap/wrapper.header文件),有各種上載方式,適合圖片文件很多的用戶。
好處:功能多,可以讓整個(gè)網(wǎng)站風(fēng)格一致。
缺陷:沒有專門給WordPress用戶的插件,要在blog里引用圖片還需要剪貼代碼。
3.Pictorialis插件
簡(jiǎn)介:這個(gè)插件是專門為了把WordPress變成圖片blog網(wǎng)站而開發(fā)的,可以從預(yù)設(shè)的目錄里讀取圖片文件,直接生成blog正文。
好處:方便需要每天上載圖片的用戶。
缺陷:不太適合圖片非常多,只想在正文中引用少數(shù)圖片的用戶,上載功能比較有限。
當(dāng)前題目:wordpress相冊(cè) wordpress相冊(cè)主題
當(dāng)前路徑:http://muchs.cn/article4/dohscoe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、標(biāo)簽優(yōu)化、搜索引擎優(yōu)化、服務(wù)器托管、靜態(tài)網(wǎng)站、品牌網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)