如果类别或文章视图,Php Joomla显示/隐藏页面标题

I need to edit this code in a Joomla template so that it shows the page heading (id="jf_page_heading") only when I'm in category blog view and hide it when I'm inside the article.

<?php
            $menu               = JFactory::getApplication()->getMenu();
            $active             = $menu->getActive();
            if (is_object($active)) {
                $pageHeading        = $active->params->get('page_heading');
                $show_pageHeading   = $active->params->get('show_page_heading');
                // CALL
                if($pageHeading != ''){ // or - if($pageHeading != '' && $show_pageHeading){
        ?>
            <div id="jf_page_heading">
                <div class="rt-container">
                    <div class="rt-block">
                        <h1><?php echo $pageHeading; ?></h1>
                        <?php echo $gantry->displayModules('jf-page-heading','basic','basic'); ?>
                        <div class="clear"></div>
                    </div>
                </div>
            </div>
        <?php } } ?>

How should I edit it?

Try something like

$input = JFactory::getApplication()->input; 
if (
  $input->getCmd('option') == 'com_content' &&
  $input->getCmd('layout') == 'blog' &&
  $input->getCmd('view') == 'category'
) {
    // Show title
}
  1. To show page heading in category blog view, you don't need to edit the code. Rather you can simply enable the show page heading parameter in your category blog menu. For hiding the page heading in article view, you need create a override for it in your template folder.

    Article path: site/templates/html/com_content/article/default.php

    Comment the page heading html section you want to hide.

  2. Alternative way, if you want to do it through code as you are using gantry template in category blog view if the code is not present - You should not check $pageheading in if condition but check the show_pageHeading variable.

    Category-blog path: site/templates/html/com_content/category/blog.php

       <?php $menu  = JFactory::getApplication()->getMenu();
        $active = $menu->getActive();
        if (is_object($active)) {
        $pageHeading        = $active->params->get('page_heading');
        $show_pageHeading   = $active->params->get('show_page_heading'); // returns 1 or 0 if set to Yes or no in menu item
        // check if showpageheading is set in menu item
       if($show_pageHeading){ ?>
        <div id="jf_page_heading">
        <div class="rt-container">
            <div class="rt-block">
                <h1><?php echo $pageHeading; ?></h1>
                <?php echo $gantry->displayModules('jf-page-heading','basic','basic'); ?>
            <div class="clear"></div>
            </div>
       </div>
       </div>
      <?php } } ?>
    

Follow point(1) for hiding page-heading in article view.

Hope this helps.