web-dev-qa-db-fra.com

Tout code court disponible pour Get Post List avec Thumbnail Plugin?

N'importe quel code court disponible pour Obtenir la liste de diffusion avec la miniature Plugin? ou bien comment créer un code court pour ce plugin particulier? Merci d'avance.

1
Ramkumar M

voici une solution rapide pour en faire un shortcode: collez ce code dans le fichier functions.php de votre thème:

add_shortcode('gplt','getPostListThumbs_shortcode');
function getPostListThumbs_shortcode($atts, $content = null){

    extract(shortcode_atts(array(
        'orient' => 'v',
        'imgo' => false,
        'ttgo' => false,
        'dtgo' => false,
        'dtfrm' => 1,
        'categ' => '',
        'postnr' => 20,
        'linn' => 3,
        'tbwid' => 40,
        'tbhig' => 40       
    ), $atts));
    $orient = gtpartrat($orient,'v');
    $imgo = gtpartrat($imgo,false);
    $ttgo = gtpartrat($ttgo,false);
    $dtgo = gtpartrat($dtgo,false);
    $dtfrm = gtpartrat($dtfrm,1);
    $categ = gtpartrat($categ,'');
    $postnr = gtpartrat($postnr,20);
    $linn = gtpartrat($linn,3);
    $tbwid = gtpartrat($tbwid,40);
    $tbhig = gtpartrat($tbhig,40);

    $htmlcod = "<table id='div_postlist' width='".$divwid."' cellpadding='4' cellspacing='4'>"."\n";
    $htmlcod .= "<tr>"."\n";
    //
    if (have_posts()) :
        global $post;

        if($categ!=''){
            $strquery = "numberposts=".$postnr."&category_name=". $categ;
        }
        else{
              $strquery =  "numberposts=".$postnr;
        }

        $myposts=get_posts($strquery);

        $ctxtr = 0;
        switch($dtfrm){
            case 1:
                $dtdis = 'd/m/y';
            break;
            case 2:
                $dtdis = 'm/d/y';
            break;
        }
        if($myposts):

        foreach($myposts as $post) :

                    $args = array(
                        'post_type' => 'attachment',
                        'numberposts' => -1,
                        'post_status' => null,
                        'post_parent' => $post->ID
                    );
                    $attachments = get_posts($args);


                    $imgsrc = "";
                    if ($attachments):

                        foreach ($attachments as $attachment) {

                            $imgsrc = wp_get_attachment_image($attachment->ID, array($tbwid,$tbhig), $icon = false);
                            break;
                        }
                    endif;

                    if($orient=="v"){     
                            if($ctxtr == 0){
                                $htmlcod .= "<tr>"."\n";
                            } 
                            $ctxtr = $ctxtr + 1;

                                $htmlcod .= "<td valign='top'>"."\n";
                            if($imgsrc!=""):                           
                                $htmlcod .= "<a href='". get_permalink() ."' title='". get_the_title() ."'>"."\n";
                                $htmlcod .= $imgsrc;
                                $htmlcod .= "</a>"."\n";                           
                            endif;
                                $htmlcod .= "</td>"."\n";

                            if(!$imgo){           
                                $htmlcod .= "<td valign='top'>"."\n";
                                if($dtgo):
                                $htmlcod .= "<p>".get_the_time($dtdis)."</p>";
                                endif;
                                if($ttgo):
                                $htmlcod .= "<a href='". get_permalink()."' title='". get_the_title() ."'>";
                                $htmlcod .= get_the_title();
                                $htmlcod .= "</a>"."\n";
                                endif;
                                $htmlcod .= "</td>"."\n";
                            }
                            $htmlcod .= "</tr><tr>"."\n";  
                    }
                    else{

                            if($ctxtr == 0){
                                $htmlcod .= "<tr>"."\n";
                            }      
                            $ctxtr = $ctxtr + 1;                      
                            $htmlcod .= "<td valign='top'>"."\n";
                            $htmlcod .= "<table cellpadding='3' cellspacing='3' border='0' width='100%'>"."\n";

                                $htmlcod .= "<tr>"."\n";
                                $htmlcod .= "<td valign='top'>"."\n";
                            if($imgsrc!=""):                           
                                $htmlcod .= "<a href='". get_permalink() ."' title='". get_the_title() ."'>"."\n";
                                $htmlcod .= $imgsrc;
                                $htmlcod .= "</a>"."\n";    
                                $htmlcod .= "</td>"."\n";                       
                            endif;

                            if(!$imgo){  
                                $htmlcod .= "<td valign='top'>"."\n";             
                                if($dtgo):
                                $htmlcod .= "<p>".get_the_time($dtdis)."</p>";
                                endif;
                                if($ttgo):
                                $htmlcod .= "<a href='". get_permalink()."' title='". get_the_title() ."'>";
                                $htmlcod .= get_the_title();
                                $htmlcod .= "</a>"."\n";
                                endif;      
                                $htmlcod .= "</td>"."\n";                         
                            }
                            $htmlcod .= "</td>"."\n";
                            $htmlcod .= "</tr>"."\n";
                            $htmlcod .= "</table>"."\n";
                            $htmlcod .= "</td>"."\n";
                            if($ctxtr == $linn){
                                $htmlcod .= "</tr>"."\n";
                                $ctxtr = 0;
                            }
                    }
        endforeach;
        else:
            $htmlcod = "<tr>"."\n";
            $htmlcod = "<td>"."\n";
            $htmlcod .= "No registers found."."\n";
            $htmlcod .= "</td>"."\n";
            $htmlcod .= "</tr>"."\n";
        endif;
    endif;
        $htmlcod .= "</table>";
    return $htmlcod;
}

Utilisation:

il suffit d'appeler le shortcode [gplt parametes] depuis n'importe quel post ou une page.

paramètres:

  • Orientation: orient = "v" // v = vertical, h = valeur horizontale par défaut 'v'
  • Afficher uniquement les images: imgo = "false" // true, false par défaut 'false'
  • Titre de l'article: ttgo = "false" // true, false par défaut 'false'
  • Date d'affichage du message: dtgo = "false" // true, false par défaut 'false'
  • Format de date: dtfrm = "1" // 1 - j/m/y, 2 - m/j/y par défaut '1'
  • Nom de la catégorie: categ = '' // omis ou vide pour toutes les catégories par défaut ''
  • Nombre de messages: postnr = "20" // default = 20
  • Nombre de registres par ligne: linn = "3" // valeur par défaut = 3 uniquement pour l'orientation horizontale
  • Largeur des miniatures: tbwid = "40" // default = 40
  • Hauteur des vignettes: tbhig = "40" // default = 40
1
Bainternet

J'ai développé une nouvelle version pour Obtenir la liste des publications avec les miniatures 4.0.0 et il est maintenant possible d'utiliser des codes courts.

1
Alvaro Neto
    //Shortcode for Get Recent Post Thumbnail
add_shortcode('gplt','getPostListThumbs_shortcode');

fonction getPostListThumbs_shortcode ($ atts, $ content = null) {

extract(shortcode_atts(array(
    'orient' => 'v',
    'imgo' => true,
    'ttgo' => true,
    'dtgo' => false,
    'dtfrm' => 1,
    'categ' => '',
    'postnr' => 500,
    'linn' => 3,
    'tbwid' => 175,
    'tbhig' => 100       
), $atts));
$orient = gtpartrat($orient,'v');
$imgo = gtpartrat($imgo,false);
$ttgo = gtpartrat($ttgo,false);
$dtgo = gtpartrat($dtgo,false);
$dtfrm = gtpartrat($dtfrm,1);
$categ = gtpartrat($categ,'');
$postnr = gtpartrat($postnr,500);
$linn = gtpartrat($linn,3);
$tbwid = gtpartrat($tbwid,175);
$tbhig = gtpartrat($tbhig,100);

$htmlcod = "<table id='div_postlist' width='".$divwid."' cellpadding='4' cellspacing='4'>"."\n";
$htmlcod .= "<tr>"."\n";
//

// if (have_posts ()): global $ post;

    if($categ!=''){
        $strquery = "numberposts=".$postnr."&category_name=". $categ;
    }
    else{
          $strquery =  "numberposts=".$postnr;
    }

    $myposts=get_posts($strquery);

    $ctxtr = 0;
    switch($dtfrm){
        case 1:
            $dtdis = 'd/m/y';
        break;
        case 2:
            $dtdis = 'm/d/y';
        break;
    }
    if($myposts):

    foreach($myposts as $post) :

                $args = array(
                    'post_type' => 'attachment',
                    'numberposts' => -1,
                    'post_status' => null,
                    'post_parent' => $post->ID
                );
                $attachments = get_posts($args);


                $imgsrc = "";
                if ($attachments):

                    foreach ($attachments as $attachment) {

                        $imgsrc = wp_get_attachment_image($attachment->ID, array($tbwid,$tbhig), $icon = false);
                        break;
                    }
                endif;

                if($orient=="v"){     
                        if($ctxtr == 0){
                            $htmlcod .= "<tr>"."\n";
                        } 
                        $ctxtr = $ctxtr + 1;

                            $htmlcod .= "<td valign='top'>"."\n";
                        if($imgsrc!=""):                           
                            $htmlcod .= "<a href='". get_permalink() ."' title='". get_the_title() ."'>"."\n";
                            $htmlcod .= $imgsrc;
                            $htmlcod .= "</a>"."\n";                           
                        endif;
                            $htmlcod .= "</td>"."\n";

                        if(!$imgo){           
                            $htmlcod .= "<td valign='top'>"."\n";
                            if($dtgo):
                            $htmlcod .= "<p>".get_the_time($dtdis)."</p>";
                            endif;
                            if($ttgo):
                            $htmlcod .= "<a href='". get_permalink()."' title='". get_the_title() ."'>";
                            $htmlcod .= get_the_title();
                            $htmlcod .= "</a>"."\n";
                            endif;
                            $htmlcod .= "</td>"."\n";
                        }
                        $htmlcod .= "</tr><tr>"."\n";  
                }
                else{

                        if($ctxtr == 0){
                            $htmlcod .= "<tr>"."\n";
                        }      
                        $ctxtr = $ctxtr + 1;                      
                        $htmlcod .= "<td valign='top'>"."\n";
                        $htmlcod .= "<table cellpadding='3' cellspacing='3' border='0' width='100%'>"."\n";

                            $htmlcod .= "<tr>"."\n";
                            $htmlcod .= "<td valign='top'>"."\n";
                        if($imgsrc!=""):                           
                            $htmlcod .= "<a href='". get_permalink() ."' title='". get_the_title() ."'>"."\n";
                            $htmlcod .= $imgsrc;
                            $htmlcod .= "</a>"."\n";    
                            $htmlcod .= "</td>"."\n";                       
                        endif;

                        if(!$imgo){  
                            $htmlcod .= "<td valign='top'>"."\n";             
                            if($dtgo):
                            $htmlcod .= "<p>".get_the_time($dtdis)."</p>";
                            endif;
                            if($ttgo):
                            $htmlcod .= "<a href='". get_permalink()."' title='". get_the_title() ."'>";
                            $htmlcod .= get_the_title();
                            $htmlcod .= "</a>"."\n";
                            endif;      
                            $htmlcod .= "</td>"."\n";                         
                        }
                        $htmlcod .= "</td>"."\n";
                        $htmlcod .= "</tr>"."\n";
                        $htmlcod .= "</table>"."\n";
                        $htmlcod .= "</td>"."\n";
                        if($ctxtr == $linn){
                            $htmlcod .= "</tr>"."\n";
                            $ctxtr = 0;
                        }
                }
    endforeach;
    else:
        $htmlcod = "<tr>"."\n";
        $htmlcod = "<td>"."\n";
        $htmlcod .= "No registers found."."\n";
        $htmlcod .= "</td>"."\n";
        $htmlcod .= "</tr>"."\n";
    endif;
// endif;
    $htmlcod .= "</table>";
return $htmlcod;

} J'ai trouvé le bogue dans cette ligne 'if (have_posts ()):'. Nous devons créer des lignes de commentaire. 1.//if (have_posts ()): 2. // endif; Maintenant ça marche bien.Hurrahhhhh.Merci Bainternet :)

0
Ramkumar M