• I’m currently playing around with the page.php file to try and have it display certain information if the page has a specific title.

    I’ll try and explain what I’m trying to do.

    I was to create a ‘portfolios’ page in wordpress, which will then have a number of children pages underneath it. I want the portfolios page to display links to all the children pages as thumbnails. If the page is not the portfolios page I just want it to display as a standard page.

    I’m trying to figure out how to code this using something like:

    <?php if (is_page('Portfolios')) {
    DISPLAY THUMBNAILS HERE
    } else {
    THE USUAL PAGE CODE HERE
    } ?>

    In theory I think something like that should work. The two questions I have are 1. am I on the right track? and 2. how would I just display children of the ‘Portfolios’ page in the ‘DISPLAY THUMBNAILS HERE’ section I’ve blocked out above?

    Any advice/help is appreciated.
    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter swollenpickles

    (@swollenpickles)

    Thanks. It’s not so much the thumbnail thing I’m having problems with, but more how to display the children of the page if the page has a specific title (eg. Portfolios).

    Thread Starter swollenpickles

    (@swollenpickles)

    I was thinking something like this, but can’t get it functioning:

    <?php if (is_page('Portfolios')) {
    	$pages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');
    	$count = 0;
    	foreach($pages as $page)
    	{
    		$content = $page->post_content;
    		if(!$content)
    			continue;
    		if($count >= 2)
    			break;
    		$count++;
    		$content = apply_filters('the_content', $content);
    	?>
    		<h2><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></h2>
    		<div class="entry"><?php echo $content ?></div>
    	<?php
    	}	
    
    } else {
    		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    		<div class="post" id="post-<?php the_ID(); ?>">
    		<h2><?php the_title(); ?></h2>
    			<div class="entry">
    				<?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
    
    				<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    
    			</div>
    		</div>
    		<?php endwhile; endif; ?>
    	<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
    <?php } ?>

    I missed this before–but instead of playing around with the pages.php template, just create a template for Portfolios then you would just need something like this:

    <?php
    //replace post_parent value with your portfolio page id:
        $args=array(
          'post_type' => 'page',
          'post_parent' => 93,
          'post_status' => 'publish',
          'posts_per_page' => -1,
          'caller_get_posts'=> 1
          );
        $my_query = null;
        $my_query = new WP_Query($args);
        //echo "<pre>"; print_r($my_query); echo "</pre>";
        if( $my_query->have_posts() ) {
          echo 'List of Child Page of Page ID 93';
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
            <?php
            global $more; $more = false;
            the_content('Read on....');
          endwhile;
        }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    See Page Template and Template Hierarchy

    Thread Starter swollenpickles

    (@swollenpickles)

    thanks I’ll take a look at that tonight.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Displaying children of page with specific page id’ is closed to new replies.