【问题标题】:Wordpress If Parent { } else if child { } [closed]Wordpress If Parent { } else if child { } [关闭]
【发布时间】:2013-02-15 07:28:22
【问题描述】:

我会说我是 php 的菜鸟,但我觉得我至少有点了解它。

好的,所以我正在 wordpress 中制作主题,但 category.php 有问题。当 wordpress 在 category.php 中读取时,我想要一个看起来像这样的 if 语句。

<?php
$cate = get_category($cat);

if ($cate->category_parent == 1) { 
     require_once ( get_template_directory() . '/category-parent.php' ); } 
else if($cate->category_parent == 0) { 
     require_once ( get_template_directory() . '/category-child.php' ) } 
endif; ?>

是的,如果父母使用这个模板,如果孩子使用这个模板,我所说的模板是指 page.php 模板。

谢谢!

【问题讨论】:

  • . '/category-parent.php ); } => . '/category-parent.php' ); }。与“孩子”相同

标签: php wordpress parent categories


【解决方案1】:
$sep = '»';
$parents = get_category_parents( $cat, TRUE, $sep );
$parents = explode( $sep, trim( $parents, $sep ) );
if( 1 === count( $parents ) ) {
    /* No category parents. */
    require_once ( get_template_directory() . '/category-parent.php' );
}
else {
    /* One or more parent categories. */
    require_once ( get_template_directory() . '/category-child.php' );
}

【讨论】:

    猜你喜欢
    • 2018-03-29
    • 1970-01-01
    • 2017-09-05
    • 1970-01-01
    • 2019-09-04
    • 1970-01-01
    • 2016-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多