- This topic has 22 replies, 2 voices, and was last updated 2 years ago by
David.
-
AuthorPosts
-
March 21, 2018 at 6:26 pm #525894
surfing
I’m a new customer and am loving GP! I’m trying figuring out the best way to accomplish something with GP.
I want an introduction on the post archive page for each category. Each category will have its own introduction. Therefore, cars category will have an intro about cars. Then my horses category will have an intro for horses. Furthermore, I only want this introduction to be displayed on the first page of the post category archive. This article on Yoast explains what I’m want to do. How can I do this using GeneratePress?
Here’s an example on yoast.com of what I want to do.
Take a look at this post category archive:
Notice how on the first page there is an introduction, then on the second page the introduction goes away? This is what I want to do. What the best way to achieve this with GP?Thanks
GeneratePress 2.0.2GP Premium 1.5.6March 21, 2018 at 9:02 pm #525970Leo
StaffCustomer SupportHi there,
I believe our page header add-on is what you are looking for:
https://docs.generatepress.com/article/page-header-overview/
https://docs.generatepress.com/article/page-header-global-locations/#post-types-%E2%80%93-archivesThen I think we can use some CSS to hide it on second page.
Let me know when you set things up.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/March 21, 2018 at 10:25 pm #526008surfing
Leo thanks for the reply.
I want to have unique content for each category archive page and I have 8 categories on my site. Therefore, I have created unique page headers for each category and then assigned these page headers to the corresponding category. Now this works good thus far but I see the page headers on the second page and beyond. Which is the part I’m not sure how to do with GP. Are you suggesting I use CSS display:none; to eliminate the header on category archive pages 2+? What’s the code for this and where should it go?
Alternatively, For each category can I use the description field and then do a display:none; to remove the description for pages 2+?
Any help will be appreciated.
March 22, 2018 at 10:09 am #526557Tom
Lead DeveloperLead DeveloperFor the Page Header, you can do this:
.paged .page-header-content { display: none; }
For the standard category description, you can do this:
.paged .page-header { display: none; }
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 22, 2018 at 11:47 pm #527388surfing
After adding the recommended CSS code I am noticing when I view page source, the category description is still within the page but not displayed. I don’t think a CSS based approach will work for what I trying to do. I need for the category description to not be present when viewing page source. I am trying to eliminate duplicate content from my site and using CSS will not fix the problem. Google will still index this content.
How can something like the following be accomplished using the WordPress title and WordPress category description?
1) WP Title and WP category description are displayed on the first page of a category archive.
2) On subsequent pages (paginated archive pages) only the WP Title is displayed with the word “Archives” without the quotes added within the H1 tag. To see what I mean please look at this category page on Yoast then go to page two. These two pages on Yoast show what I describe above.I’m guessing a PHP based approach is required. After looking around on wordpress.org, I think I will need to make a modification to this code, but not sure how to do it within GP theme.
<?php if ( have_posts() ) : ?> <header class="page-header"> <?php the_archive_title( '<h1 class="page-title">', '</h1>' ); the_archive_description( '<div class="taxonomy-description">', '</div>' ); ?> </header><!-- .page-header -->
If you have a better idea please let me know.
Any help will be appreciated.
March 23, 2018 at 9:42 am #528170Tom
Lead DeveloperLead DeveloperGive this function a try:
add_action( 'wp', 'tu_remove_paged_category_description' ); function tu_remove_paged_category_description() { $page = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; if ( 1 !== $page ) { remove_action( 'generate_archive_title', 'generate_archive_title' ); } }
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 23, 2018 at 10:09 am #528212surfing
Thanks for the reply. Where should I insert this function? Within Hooks or a particular PHP page?
March 23, 2018 at 10:17 am #528226Tom
Lead DeveloperLead DeveloperOne of these methods is best: https://docs.generatepress.com/article/adding-php/
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 23, 2018 at 11:18 am #528310surfing
I used Code Snippets and inserted the code but get a white screen below the site header. Any idea what I should do next?
March 23, 2018 at 11:23 am #528316Tom
Lead DeveloperLead DeveloperThat’s strange. I just adjusted the code above, can you try it instead?: https://generatepress.com/forums/topic/custom-intro-for-each-category-archive-for-first-page-only/#post-528170
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 23, 2018 at 12:49 pm #528423surfing
Thanks for your help Tom.
It looks like I had conflicting code in a hook. Once I removed all the hooks and used the first code you sent it worked. The second try didn’t work. Below is the code which worked
add_action( 'wp', 'tu_remove_paged_category_description' ); function tu_remove_paged_category_description() { $page = (get_query_var('paged')) ? get_query_var('paged') : 1; if ( 1 !== $page ) { remove_action( 'generate_archive_title', 'generate_archive_title' ); } }
I need one more small adjustment. How can the Category title be displayed on pages 2+ with the word Archives appended? Here is a summary of it all in one place:
1) WP Title and WP category description are displayed on the first page of a category archive.
2) On subsequent pages (paginated archive pages) only the WP Title is displayed with the word “Archives” without the quotes added within the H1 tag.For example if the category is Dogs and there is a Dogs description. Then the first page will show the title Dogs and the Dogs description. The subsequent pages will show Dogs Archives for the title without showing the description.
March 23, 2018 at 8:59 pm #528809Tom
Lead DeveloperLead DeveloperYou can try adjusting the function to this:
add_action( 'wp', 'tu_remove_paged_category_description' ); function tu_remove_paged_category_description() { $page = (get_query_var('paged')) ? get_query_var('paged') : 1; if ( 1 !== $page ) { remove_action( 'generate_archive_title', 'generate_archive_title' ); add_action( 'generate_archive_title', 'tu_custom_paged_archive_title' ); } } function tu_custom_paged_archive_title() { ?> <header class="page-header"> <h1 class="page-title"> <?php the_archive_title(); ?> Archives </h1> </header> <?php }
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 23, 2018 at 11:50 pm #528911surfing
Thanks! Works great!
March 24, 2018 at 8:57 am #529326Tom
Lead DeveloperLead DeveloperYou’re welcome 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentJanuary 14, 2021 at 3:55 am #1618204David
Hi Tom,
What about if I am using an Elements Header on my Archive Category pages and showing the description.
But then the code above does not prevent the description from not showing on pages 2, 3, 4, ….
I can not use php in an Element Header, so any ideas?
-
AuthorPosts
- You must be logged in to reply to this topic.