wp_get_attachment_image_src () et tailles personnalisées
1 réponses
- votes
-
- 2014-04-06
Vous avezmal lu le Codex.
wp_get_attachment_image_src()
fonctionnetrèsbien avec destailles d'imagepersonnalisées.Preuve de concept:
// copied from the Codex // https://codex.wordpress.org/Function_Reference/add_image_size if ( function_exists( 'add_image_size' ) ) { add_image_size( 'category-thumb', 300, 9999 ); //300 pixels wide (and unlimited height) add_image_size( 'homepage-thumb', 220, 180, true ); //(cropped) }
Ajoutez uneimage à labibliothèque,puis ...
$image_attributes = wp_get_attachment_image_src( 28, 'category-thumb' ); var_dump($image_attributes);
Vous remarquerez que l'image renvoyéeest (une approximation de) 300x9999 - c'est-à-dire 300 de large quelle que soit l'échelle de hauteur.
You are misreading the Codex.
wp_get_attachment_image_src()
works just fine with custom image sizes.Proof of concept:
// copied from the Codex // https://codex.wordpress.org/Function_Reference/add_image_size if ( function_exists( 'add_image_size' ) ) { add_image_size( 'category-thumb', 300, 9999 ); //300 pixels wide (and unlimited height) add_image_size( 'homepage-thumb', 220, 180, true ); //(cropped) }
Add an image to the Library, then...
$image_attributes = wp_get_attachment_image_src( 28, 'category-thumb' ); var_dump($image_attributes);
You will notice that the image returned is (an appromixation of) 300x9999-- that is 300 wide by whatever height scales correctly.
-
mercimais cen'estpas unepreuve,je suis déjà des choses var_dumppour le voir.N'obtenez que lespouces d'origine.Je suppose que la véritéest ailleurs,je suis sur wpbeta 3.9 3,je ne saispas si cela comptethanks but that is not a proof, I'm already var_dump things to see it. Get nothing but the original thumbs. Guess the truth is elsewhere, I'm on wp beta 3.9 3, do not know if that matters
- 0
- 2014-04-06
- JMau
-
Fonctionne quandje l'essayeet qu'iln'y a [rien dans la source] (https://core.trac.wordpress.org/browser/tags/3.8.1/src/wp-includes/media.php#L509) queje voiscela limiterait lestailles.Leproblème que vous rencontrezne résidepas là où vous lepensez,j'en suispresque sûr.Testé sur 3.9.Works when I try it and there is [nothing in the source](https://core.trac.wordpress.org/browser/tags/3.8.1/src/wp-includes/media.php#L509) that I see that would limit the sizes. The problem you are having does not lie where you think it does, I am pretty sure. Tested on 3.9.
- 0
- 2014-04-06
- s_ha_dum
-
Je suppose quetu as raison,je ne voispas ça aussi.`$ size`est une chaîne.I guess you're right I do not see that too. `$size` is a string.
- 0
- 2014-04-06
- JMau
-
Mais c'estbizarre,celane fonctionne qu'avec destaillesintégréespourmoi!But it's weird it workw only with built-in sizes for me !
- 0
- 2014-04-06
- JMau
-
Il y a autre chose quine vapas.Essayez avec unthèmefourniet sansplugins.There is something else wrong. Try with a bundled theme and no plugins.
- 0
- 2014-04-06
- s_ha_dum
-
J'ajoute +1pour votre réponse carje pense que vous avez raisonmais leproblèmeesttoujours là.Quandje var_dumpj'obtiens unfauxpour le quatrième élément dutableau oOI add +1 for your answer because I think you're right but the problem is still there. When I var_dump I get a false for the fourth element of the array oO
- 0
- 2014-04-06
- JMau
-
Le quatrième élémentest "` [3]=>booléen`: `true` si` $ url`est uneimage redimensionnée,`false` si c'est l'original."Jene voispaspourquoi celaestpertinent.Deuxièmement,je crois que vous rencontrez leproblème que vous décrivez,mais cela répond à la questionposéeet iln'y a aucunmoyen de deviner quoi d'autrepourraitbriser les choses.The fourth element is "`[3] => boolean`: `true` if `$url` is a resized image, `false` if it is the original." I fail to see why that is relevant. Secondly, I believe that are experiencing the problem you describe but this does answer the question as asked and there is no way to guess at what else might be breaking things.
- 0
- 2014-04-06
- s_ha_dum
-
Je le sais déjàparce queje me concentre sur cet élémentparticulier dutableau,maismerci.Leproblèmeiciest que leparamètre $ size de `wp_get_attachment_image_src ()`est un $ var dansmon code.I already know that because I'm focusing on this particular element of the array but thank you. The chase here is that the $size param of `wp_get_attachment_image_src()` is a $var in my code.
- 0
- 2014-04-06
- JMau
-
Si cettepartie de la sortieest leproblème,votre questionestextrêmementtrompeuse.If that part of the output is the problem, then your question is extremely misleading.
- 0
- 2014-04-06
- s_ha_dum
-
Jepensais que c'était unbug de WP avant de demanderici ^^I thought it was a bug of WP before asking here ^^
- 0
- 2014-04-06
- JMau
-
Votre questionn'a vraiment rien à voir avec le contenu spécifique de ce quatrième élément detableau.Your question really has nothing to do with the specific content of that fourth array element.
- 0
- 2014-04-06
- s_ha_dum
-
ce quatrième élémentmontre si c'est uneimage redimensionnée oupas,doncen effetil atout à voir avecelle.Mais commeje l'ai dit ungrandmerciet désolé de vous déranger avecmes questions stupides ^^this fourth element shows if it's a resized image or not so indeed it has everything to do with it. But as I said big thanks and sorry to bother you with my stupid questions ^^
- 0
- 2014-04-06
- JMau
-
N'oubliezpas que vous devez régénérertoutes lesminiaturespour que lanouvelletaillepersonnaliséefonctionne.Vouspouvez lefaire avec du code ou avec leplugin "Regeneratethumbnails".Remember you need to regenerate all thumbnails in order for the new custom size to work. You can do this with code or with the plugin "Regenerate thumbnails".
- 1
- 2019-09-16
- Floris
Commeindiqué sur cettepage ,
wp_get_attachment_image_src()
n'accepte quetaillesintégréestelles que vignette,moyenne,grande oupleine.Comment obtenir lamême valeur de retour avec lestaillespersonnalisées que vous ajoutez avec
add_image_sizes()
?