K
K
Konstantin2020-06-20 19:01:40
WordPress
Konstantin, 2020-06-20 19:01:40

The question is how to write a condition so that on the shop page it simply displays the word “products”, and on others the name of the category?

I had a problem that the title was displayed in the category: Archives: Category name, but I did not like that the word "Archives" was displayed and I was advised

<?php the_archive_title( '', '' );; ?>

to replace it with
<?php single_term_title() ?>

Now it is displayed in the categories as it should, but the text "products" is not displayed on the shop page.

The question is how to write a condition so that on the shop page it simply displays the word "products", and on others the name of the category. I don't know PHP.

Source:

<div class="banner-shop">
            <?php if ( is_home() ) : ?>
                <?php if( is_front_page()):?>
                    <h1 class="page-title blog-title"><?php esc_html_e('Latest Posts','organics');?></h1>
                <?php else:?>
                    <h1 class="page-title blog-title"><?php single_post_title(); ?></h1>
                <?php endif;?>
            <?php elseif( is_single() ):?>
            <?php elseif( is_page() ):?>
                <h1  class="page-title"><?php the_title(); ?></h1>
            <?php else:?>
                <h1  class="page-title"><?php single_term_title() ?></h1>
                <?php
                ?>
            <?php endif;?>
       </div>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Sedov, 2020-06-20
@gradk

<?php if (is_shop()) : ?>
  <h1 class="page-title">Товары</h1>
<?php else : ?>
  <h1 class="page-title"><?php single_term_title() ?></h1>
<?php endif; ?>

S
Sergey Ermilov, 2020-06-21
@sergeiermilov

Here you did not write what "Shop page" means - is it a category, is it a page or a WooCommerce store?
If this is a rubric, then the easiest option is to do this:

<?php if ( is_category( 'shop' ) { ?>
    <h1>Товары</h1>
<?php } else { ?>
    <h1><?php single_cat_title(); ?></h1>
<?php }; ?>

If you have a page (which is unlikely), then almost the same:
<?php if ( is_page( 'shop' ) { ?>
    <h1>Товары</h1>
<?php } else { ?>
    <h1><?php single_cat_title(); ?></h1>
<?php }; ?>

If you have WooCommerce, then in the same place a separate template is used for the store.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question