【问题标题】:Make the condition to hide header on child pages Wordpess设置条件在子页面 Wordpress 上隐藏标题
【发布时间】:2018-01-15 15:28:24
【问题描述】:

我遇到了在 WordPress CMS 上隐藏特定目录页面上的标题的问题。

是否可以创建一个 php-code 条件,不按条件在某个目录中的所有页面上显示标题:

喜欢

<?php if( $some_page => have 'users' in $url ) : ?>
    <header style="display:none"></header>
<?php else......
<?php endif....

附言

我知道任何页面上都有一个很棒的 css 魔术插件,但是我的页面太多了...

【问题讨论】:

  • 我投票结束这个问题,因为这个问题属于wordpress.stackexchange.com
  • body:not(.home/index/whatever) .page-header { display: none; } 这样的东西可能使用 css 工作,尽管您的主题需要使用 &lt;body &lt;?php body_class(); ?&gt;&gt;
  • 我建议不要用 css 做这个。编写一个检查所需条件的函数。如果该函数返回 true,则加载标头,否则不加载。执行 display none 可能会隐藏元素,但仍会呈现该元素。但是如果你用 php 来做,它不会在你不想显示的页面中呈现。
  • @KrishnadasPC 感谢您的解释。但我不需要解释(我和你一样都知道),我需要有效的解决方案。我已经成功了。干杯!

标签: php css wordpress


【解决方案1】:

CSS 解决方案

假设您的主页body 类:&lt;body class="index"&gt; 和您的标题&lt;header class="page-header"&gt;text&lt;/header&gt;

你可以使用这个类来显示或不显示标题,使用这个方法。

body:not(.index) .page-header { display: none; }  

希望对你有帮助。

【讨论】:

    【解决方案2】:

    我找到了一个简单的解决方案:

    我们可以通过stristr() func 在其中的符号或短语的url中进行简单的搜索。所以条件会是下一个:

    <?php $current_page = get_page_link() ?>
    
    <?php if (stristr($current_page, "user") == true) : ?>              // if "url" have 
        <h1 class="entry-title h1" style="display:none;"></h1>          // phrase 'user' 
    <?php else : ?>                                                     // in it the header will not show
        <?php the_title( '<h1 class="entry-title h1">', '</h1>' ); ?>   // header 
        <h1 class="entry-title h1"></h1>                                // show without any problem
    <?php endif; ?>
    

    【讨论】:

      【解决方案3】:

      我对你的回答做了一些修改。

          <?php $current_page = get_page_link() ?>
      
          <?php if (stristr($current_page, "user") === false) : ?> 
          <?php the_title( '<h1 class="entry-title h1">', '</h1>' ); ?>   
          <?php endif; ?>
      //If you don't want to render anything on true condition no need to render anything.
      

      使用=== 也可以检查类型。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-20
        • 2018-09-08
        • 2022-10-06
        • 2018-04-07
        • 1970-01-01
        相关资源
        最近更新 更多