- This topic has 20 replies, 2 voices, and was last updated 2 years, 4 months ago by
Tom.
-
AuthorPosts
-
July 19, 2016 at 4:35 am #211207
Yomi
Hi Tom,
The theme shows category description in the category archive page. I want the description to be shown on the MAIN page only of the category but not on the other category sub pages. how can I stop sub-pages from showing the description.
I have found some code on the link below but cannot figure how to effectively use it
Please advice on the best way to get the category description to show only on the main page of the category
Below is the link to the codes I got
removing category description from category subpages
Kind regards
July 19, 2016 at 8:58 am #211263Tom
Lead DeveloperLead DeveloperCurrently, GP just uses the default WordPress way of displaying the category description, which adds it to every page (to describe the posts below).
If you need to change it, you would need to copy the archive.php file and add it to your child theme.
Then you would need to find the category_description() function, and replace it with something like this:
$page = (get_query_var('paged')) ? get_query_var('paged') : 1; if ($page == 1) { echo category_description(); }
Trouble with that is you won’t get updates made to the archives.php template anymore, as it will only listen to your child theme file.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentJuly 19, 2016 at 5:00 pm #211339Yomi
Hi Tom,
Thanks for that.
Now I have copied the archive.php file over but the problem is where do i find the “category_description() function”?
I have looked in the archive.php but cannot find anything like that.
Below is what I have in the archive.php file
<?php /** * The template for displaying Archive pages. * * Learn more: http://codex.wordpress.org/Template_Hierarchy * * @package GeneratePress */ get_header(); ?> <section id="primary" <?php generate_content_class(); ?>> <main id="main" <?php generate_main_class(); ?>> <?php do_action('generate_before_main_content'); ?> <?php if ( have_posts() ) : ?> <?php do_action( 'generate_archive_title' ); ?> <?php /* Start the Loop */ ?> <?php while ( have_posts() ) : the_post(); ?> <?php /* Include the Post-Format-specific template for the content. * If you want to override this in a child theme, then include a file * called content-___.php (where ___ is the Post Format name) and that will be used instead. */ get_template_part( 'content', get_post_format() ); ?> <?php endwhile; ?> <?php generate_content_nav( 'nav-below' ); ?> <?php else : ?> <?php get_template_part( 'no-results', 'archive' ); ?> <?php endif; ?> <?php do_action('generate_after_main_content'); ?> </main><!-- #main --> </section><!-- #primary --> <?php do_action('generate_sidebars'); get_footer();
July 19, 2016 at 8:28 pm #211353Tom
Lead DeveloperLead DeveloperSorry about that – I forgot that I moved the archive titles into a function: https://gist.github.com/generatepress/fe5309693719d138dbcf84381eb9a6b3
You’ll want to adjust the $term_description code.
You can add that code as a function: https://generatepress.com/knowledgebase/adding-php-functions/
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentJuly 19, 2016 at 10:01 pm #211370Yomi
Still need some additional help Tom…
so far here is what i have done
I am using a child theme
I have copied over the archives.php file into my child theme
From what I understand now… I have to place a code in my functions file to achieve my goal
…. what code should i place directly in the functions file of my child theme?
Please help with the code
July 19, 2016 at 11:41 pm #211376Tom
Lead DeveloperLead DeveloperYou no longer need archive.php – you can delete that file from your child theme.
Give this function a try: https://gist.github.com/generatepress/cc2d8b578c8c3706dcefe68234ca5c9f
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentJuly 20, 2016 at 1:01 am #211386Yomi
Excellent!!! 🙂
Absolutely love it….
Works like a charm once I removed the
endif;
at the end of the codeMany thanks
July 20, 2016 at 8:59 am #211470Tom
Lead DeveloperLead DeveloperThat endif; should be essential.. It should actually crash completely without it.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentNovember 5, 2016 at 9:59 am #241960Janet Davis
Tom,
Please help…
I too only want the category description on the first page of the category.
I used the above code fromhttps://gist.github.com/generatepress/cc2d8b578c8c3706dcefe68234ca5c9f
as you wrote it.
I’m using code snippets plugin.The catalog description still shows on the category sub pages.
Thank you
JanNovember 5, 2016 at 10:53 am #241983Tom
Lead DeveloperLead DeveloperInteresting, that code should work.
Is your code snippet activated?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentNovember 5, 2016 at 11:26 am #241990Janet Davis
Is seems to be. I’m using 2 other snippets that are working.
Here is page 2 of the category
https://everydayhomesteading.com/category/raising-livestock/irish-dexter-cattle/meet-our-dexters/page/2/
thank you
JanNovember 5, 2016 at 8:00 pm #242066Tom
Lead DeveloperLead DeveloperHmm, I just tried it myself and it is indeed working.
One thing you can try is this CSS instead:
.paged .taxonomy-description { display: none; }
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentNovember 5, 2016 at 8:07 pm #242072Janet Davis
Tom,
THank you that worked like a charm!
Why use CSS over the snippet coding or vice versus?
JanNovember 5, 2016 at 11:15 pm #242088Tom
Lead DeveloperLead DeveloperThe CSS just hides it, while the PHP removes it completely from the page.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentFebruary 24, 2019 at 5:28 am #819610Dmitry Bychenko
Thanks, Tom,
css works good, but there is a gap between Page Title and first post on Archive page.
What php to use to remove category descriptions from all Archive page, including the first page of the category?
-
AuthorPosts
- You must be logged in to reply to this topic.