WordPress.org

Support

Support » Themes and Templates » Subpage get parent page slug

Subpage get parent page slug

Viewing 3 replies - 1 through 3 (of 3 total)
  • Resolved thanks to KMxRetro of RewiredMind

    <?php if (is_page()) { ?>
    <?php $cssdir = get_permalink(); ?>
    <?php $holder = explode("/",$cssdir) ?>
    <link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/page.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/<?php echo $holder[3]; ?>/style.css" type="text/css" media="screen" />
    <?php } ?>

    May work differently on a different URL structure, but works on my template – so far so good.

    barriecalver
    Member

    @barriecalver

    This is an alternative I found and constructed from all the help on the forums here so thought this was the best place to post as it was so very close but no cigar for me:

    <?php
    $parent = get_page($post->post_parent);
    $grandparent = $parent->post_parent;
    ?>
    
    <?php
    
    if ( is_page('corporate-training') || $post->post_parent == '59' || $grandparent == '59' ) {
        $stylesetting = 'training.css';
    
    } elseif ( is_page('hotbedfest') || $post->post_parent == '55' || $grandparent == '55' ) {
        $stylesetting = 'hotbed.css';
    
    } elseif ( is_page('productions') || $post->post_parent == '10' || $grandparent == '10' ) {
        $stylesetting = 'productions.css';
    
    } else {
        $stylesetting = 'style.css'; // Fall-through
    }	
    
    ?>
    
    <link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/<?php echo $stylesetting; ?>" type="text/css" media="screen" />

    Thanks to all you great people..

    refugee43
    Member

    @refugee43

    I am having a similar problem. I used a conditional to change the banner, background, etc. on a couple of pages. However, the subpages to those pages revert back to the default style. In my header.php I posted the following code:

    <?php if (is_page('creation')) { ?>
    <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/style_creation.css" type="text/css">
    <?php }; ?>
    <?php if (is_page('anarchism')) { ?>
    <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/style_anarchism.css" type="text/css">
    <?php }; ?>

    This works fine for those particular pages. But like I said, the subpages revert to default. I am not quite sure how to get the subpages to follow suit.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Subpage get parent page slug’ is closed to new replies.