- This topic has 22 replies, 3 voices, and was last updated 3 years, 2 months ago by Tom.
-
AuthorPosts
-
February 2, 2021 at 1:34 am #1642547Johan
Hello and thank you for your great product!
However, I have a problem:
I created a child theme a “Custom Post Type” and when I display it by archive the layout is in one column (see here: https://dev1.directsolutions.fr/offres/nos-formations / or https://dev1.directsolutions.fr/offres/nos-formations/securite-incendie/).
I would like it to display in 2 or three columns. I have tried several of the solutions given in these pages without it working.
This does not work:add_filter (‘generate_blog_columns’, ‘tu_formation_columns’);
function tu_formation_columns ($ columns) {
if (is_post_type_archive (‘training’)) {
return true;
}
return $ columns;
}Could you give me a solution?
Thank you
Johan PuisaisFebruary 2, 2021 at 9:11 am #1643222DavidStaffCustomer SupportHi there
can you confirm the Post Type you have set for the
is_post_type_archive
is correct – it should beformation
February 2, 2021 at 9:28 am #1643240JohanHello and thank you David
Yes, I confirm it to you.
What is displayed here are the “custom post type” “formation” classified into categoriesFebruary 3, 2021 at 2:47 am #1643972DavidStaffCustomer SupportIn the code you provided above – you have:
if (is_post_type_archive ('training')) {
This needs to be:
if (is_post_type_archive ('formation')) {
February 3, 2021 at 3:16 am #1644001JohanYes I put “training” … in fact I am French and during the translation I forgot to modify “formation” π But yes my code is :
add_filter( 'generate_blog_columns','tu_formation_columns' ); function tu_formation_columns( $columns ) { if ( is_post_type_archive( 'formation' ) ) { return true; } return $columns; }
In fact I have looked at all the forum answers that may apply to my problem here and have tested most of them. Without results…
Is it due to the version of my GeneratePress (I have the latest one)? Because the examples given do not seem to be the same as the original code I find in my files.February 3, 2021 at 7:20 am #1644345DavidStaffCustomer SupportThat code should work – how are you adding the code to your site?
February 4, 2021 at 1:25 am #1645179JohanHello David,
Yes I added this code in the functions.php file of my child theme in “themes/generatepress_child”February 4, 2021 at 11:02 am #1645983TomLead DeveloperLead DeveloperHi there,
What if you use
nos-formations
instead?Let us know π
February 5, 2021 at 2:39 am #1646620JohanHello Tom,
I did it and I just do it again now. It doesn’t change anythingFor additional information and if this can help you, I also created an “archive-formation.php” which is not taken into account by the system while my “single-formation.php” works. It may not be related but …
February 6, 2021 at 10:09 am #1648396TomLead DeveloperLead DeveloperI suppose the first thing we need to do is figure out if our condition is right.
Does this output anything on your page?:
add_action( 'generate_before_header', function() { if ( is_post_type_archive( 'formation' ) ) { echo 'Hello world'; } } );
If not, it means the condition is wrong and needs to be tweaked.
February 8, 2021 at 4:03 am #1650041JohanHello Tom,
I just inserted this code and nothing is displayed, no “Hello Word” π
The condition of must therefore not be the right one.February 8, 2021 at 4:45 am #1650100DavidStaffCustomer SupportInstead of:
if ( is_post_type_archive( 'formation' ) ) {
try this in Tom’s function:
if ( is_category( 'formation' ) ) {
February 8, 2021 at 4:46 am #1650101JohanAfter some tests I see that
add_action (‘generate_before_header’, function () {
if (is_category ()) {
echo ‘Hello everyone’;
}
});
works, as well as “is-archive ()”February 8, 2021 at 4:48 am #1650105Johan“if ( is_category( ‘formation’ ) )” not works but “if ( is_category( ) )” Yes
And “if ( is_category( ‘nos-formations’ ) )” works only at “https://dev1.directsolutions.fr/offres/nos-formations/”
February 8, 2021 at 6:15 am #1650222DavidStaffCustomer SupportSo this should work:
add_filter( 'generate_blog_columns','tu_formation_columns' ); function tu_formation_columns( $columns ) { if ( is_category( 'nos-formations' ) ) { return true; } return $columns; }
Whatever archives does it need to be applied to?
-
AuthorPosts
- You must be logged in to reply to this topic.