Today, here is a nice piece of code to display all thumbs related to a specific page on a media pages. Very nice for galleries!
Today, here is a nice piece of code to display all thumbs related to a specific page on a media pages. Very nice for galleries!
Simply paste the following function into your functions.php file:
function wallthumb($id=false,$beforelist='<ul class="gallerythumb">',$afterlist='</ul>',$beforeitem='<li>',$afteritem='</li>'){
global $wp_query;
$goquery = $wp_query->post;//contenu de la requète
if(is_attachment()){
$ptitre = $goquery->post_title;//le titre de l'image
$idparent = $goquery->post_parent;//l'id de la page parente
if(!$id){//si pas d'id en argument, on tente de la recuperer
$id = $goquery->ID;
}
if($idparent == null || $idparent == '' || $idparent == 0){
return;//si l'image est orpheline (sans page parente) on stop la fonction
}
//$twice = get_posts('post_type=attachment&post_mime_type=image&numberposts=-1&order=ASC&post_status=null&post_parent='.$idparent);//recup des infos des pièces jointes a la page parente
$twice = get_children('post_type=attachment&post_mime_type=image&order=ASC&post_parent='.$idparent);//recup des infos des pièces jointes a la page parente
$stocklienimage = array();//pour stocker les liens images
if($twice){//si pièces jointes
foreach ($twice as $value) {//boucle
$classthumbactu = '';
if($value->ID == $id){//detection de l'image courante dans la boucle pour ajout d'une classe pour la differencier
$classthumbactu=' thumbactu';
}
$stocklienimage[$value->ID] = $beforeitem.'<a class="wallthumb'.$classthumbactu.'" href="'.get_attachment_link($value->ID).'" title="'.wp_specialchars( get_the_title($value->ID), 1 ).'" rel="attachment">'.wp_get_attachment_image( $value->ID, 'thumbnail' ).'</a>'.$afteritem;
}
}else{
return;
}
echo $beforelist.implode('', $stocklienimage).$afterlist;//affichage de la liste
}
}
Once done, you just have to call the function:
<?php wallthumb() ?>
Enjoy your gallery! Note that another version of the same code is available here.
Thanks to Julien Chauvin for this great piece of code!
7 Responses
Seems like a pretty awesome trick! Very hassle-free for the end user
Looks great! I can see some sweet potential here for previewing gallery pages.
That is a really cool hack and will come in very handy for image/photo based blogs.
I like this feature of displaying thumbs.. As a newbie could you explain the following..
Once done, you just have to call the function:
How do I do this..
Thanks..
David,
It means that you put the php wallthumb function into your page template that you want the thumbs to appear. Hope this explaination helps!
Trackbacks: