Forums

[resolved] Get parent to display specific subpage and it's whole content (5 posts)

  1. KGD2006
    Member
    Posted 2 years ago #

    So I found a template to display subpages directly on parent. I took that one and tried to implement my own template for subpages.

    I'm a total noob at php so I´m stuck with guessing.

    From the beginning: I want to display a specific subpage on a parent page. The subpage has a few specials (1 alternative title and a second field for content) With the code I have now my parent page displays all subpages and it doesn´t display my aternative title and second field field for content.

    Can please anyone check my code and help!?

    <?php
    /*
    Template Name: undersida_m_undersida2
    */
    ?>
    <?php get_header(); ?>
    <div class="main_left_undersida">
    
    <div class="postframe"><div class="post" style="width:920px; padding-bottom:20px;">
    
    <div class="content2">
    <?php get_the_content_2(); ?>
            <?php $altrubrik = get_post_meta($post->ID, 'altrubrik', $undersida = true); ?>
    
    <?php
    $my_slug = get_permalink();
    $args = array(
    	'numberposts' => -1,
    	'post_parent' => $post->ID,
    	'post_type' => 'page',
    	'post_status' => 'publish',
    	'orderby' => 'menu_order,title',
    	'order' => 'ASC'
    );
    $c = 0;
    $my_pagelist = &get_children($args);
    if ($my_pagelist) :
    foreach($my_pagelist as $my_child) :
    $c++;
    $my_child_slug = $my_slug.$my_child->post_name.'/';
    ?>
    
    <div class="tumnagel2" style="float:left;"><?php echo $my_child->post_content; ?></div>
    <div class="right"><?php include (TEMPLATEPATH . '/sidebar3.php'); ?>
    <h1 style=" float:left; padding-left:28px; width:500px"><?php  echo $altrubrik ?></h1>
    			<?php the_content_2(); ?></div>
    <?php endforeach; ?>
    <?php endif; ?>
    
    </div></div></div></div>
    
    <?php get_footer(); ?>
  2. MichaelH
    Volunteer
    Posted 2 years ago #

    the_content_2() is not a standard WordPress function..maybe your theme's function.php or a plugin is providing that. You will need to track that function down.

    Also not sure if you are asking about $altrubrik = get_post_meta($post->ID, 'altrubrik', but that gets a custom field from the 'parent' page.

  3. Harrison O.
    Member
    Posted 2 years ago #

    I don't know if I misunderstood your post, but why you just don't query the specific subpage? Just add this code to the parent page and it'll query your specific page.

    <?php $recent = new WP_Query('page_id=specific-subpage-id-here'); while($recent->have_posts()) : $recent->the_post();?>
    <h1><a href="<?php the_permalink() ?>">
      <?php the_title(); ?>
      </a></h1>
    <div id="1stcontent">
      <?php the_content(); ?>
    </div>
    <div id="2ndcontent">
      <?php if( get_post_meta($post->ID, "your-Cfield-namehere", true) ): ?>
      <?php echo get_post_meta($post->ID, "your-Cfield-namehere", $single = true); ?>
      <?php else: ?>
      no content
      <?php endif; ?>
    </div>
    <?php endwhile; ?>
  4. KGD2006
    Member
    Posted 2 years ago #

    Thank's Hfort, this solves my problem, can be very useful for me in the future as well!

  5. Harrison O.
    Member
    Posted 2 years ago #

    I am glad you sorted out.

Topic Closed

This topic has been closed to new replies.

About this Topic