Archived topic
Masonry Grid and Custom Post Types
3 replies · Started by Jorge on March 3, 2021
Hello, I have 6 Custom Post Types in a site ('houses' 'lots' 'fields' 'rentals' 'locations') And I want to motivate them all in the form of a "masonry grid" with this code I show exactly how I want the CPT 'houses' using the "Code Snippets" plugin
---
<?php
/**
* Grilla Masonry de casas
*/
add_filter( 'generate_blog_masonry','tu_portfolio_masonry' );
function tu_portfolio_masonry( $masonry ) {
if ( is_post_type_archive( 'casas' ) ) {
return 'true';
}
return $masonry;
}
---
How do I get it to show me all CPTs in the same way?
When I do another "code snippets" for another CPT it doesn't work, it tells me that I can't declare the masonry function again.
It seems like an obvious answer, but I'm a newbie to php and have tried a number of ways but only sample one CPT at a time.
I hope you understand what I am asking even if it is not so well expressed.
Thanks Jorge
----
Hola, tengo 6 Custom Post Types en un sitio ( 'casas' 'lotes' 'campos' 'alquileres' 'locaciones') Y quiero motrarlos a todos en forma de "masonry grid" con este código muestro exactamente como quiero al CPT 'casas'usando el plugin "Code Snippets"
---
<?php
/**
* Grilla Masonry de casas
*/
add_filter( 'generate_blog_masonry','tu_portfolio_masonry' );
function tu_portfolio_masonry( $masonry ) {
if ( is_post_type_archive( 'casas' ) ) {
return 'true';
}
return $masonry;
}
---
¿Como hago para que me muestre todos los CPT de la misma manera?
Cuando hago otro "code snippets" para otro CPT no funciona, me dice que no puedo declarar de nuevo la función masonry.
Parece una respuesta obvia, pero soy novato en php y he probado de varias maneras pero sólo muestra de a un CPT a la vez.
Espero me entiendas lo que pregunto aunque no esté tan bien expresado.
Gracias - Jorge
Hi there,
you can include multiple terms in the is_post_type_archive function.
So change this line:
if ( is_post_type_archive( 'casas' ) ) {
to:
if ( is_post_type_archive( array( 'casas', 'another-term', 'and-another-term' ) ) {
Thanks, David!
I imagined it was something simple, but not so much.
Thank you for the promptness of your response.
Glad to be of help!