【问题标题】:Show title only if content仅在内容时显示标题
【发布时间】:2015-06-17 12:51:29
【问题描述】:

如果<h2>title</h2> 不是子页面,我想隐藏它们。

<h2> title</h2></br>

<?php
// Globalize the $post variable;
// probably already available in this context, but just in case...
global $post;

wp_list_pages( array(
        'title_li'     => __(''), 
    // Only pages that are children of the current page
    'child_of' => $post->ID,
    // Only show one level of hierarchy
    'depth' => 1,
) );
?>

【问题讨论】:

  • 你能添加代码来检查是否没有子页面吗?

标签: php html wordpress title


【解决方案1】:

您可以使用 get_children 函数获取帖子的所有子内容。如果返回数组为空,则没有定义子页面:

<?php
   $children =& get_children( 'post_type=page' );
   if (!empty($children)) "<h2> title</h2>";
?>

文档:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-28
    • 1970-01-01
    • 2010-12-15
    • 1970-01-01
    • 2022-11-29
    • 2017-08-17
    • 2018-03-15
    • 2015-10-18
    相关资源
    最近更新 更多