WordPress.org

Ready to get started?Download WordPress

Forums

List of Subpages that works like a menu (with current_page_item class) ?? (4 posts)

  1. moolio
    Member
    Posted 4 years ago #

    I'd like to create a list of subpages that shows the page's thumbnail and its title. I modified the code from this post:

    http://wordpress.org/support/topic/349266?replies=2

    And now I have something that works in my sidebar, in a PHP widget:

    <ul class="side-nav">
    
    <?php
    $my_query = new WP_Query('post_type=page&post_parent=3&order=ASC');
     while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
    <?php $image_thumb = get_post_meta($post->ID, 'image-thumb', true); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?>
    
    <?php the_title(); ?></a></li>
    
    <?php endwhile; ?>
    </ul>

    I'd like this to function like a normal menu -- that is, the current page gets "current_page_item" class and is styled differently so you can tell you're on the page. I tried adding an if ( ) statement into the line item like so:

    <ul class="side-nav">
    <?php
    $current = $post->ID ?>
    <?php
    $my_query = new WP_Query('post_type=page&post_parent=3&order=ASC');
     while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
    <?php $image_thumb = get_post_meta($post->ID, 'image-thumb', true); ?>
    <li<?php if($current == $post->ID) { echo ' class="current_page_item"'; }?>><a href="<?php the_permalink(); ?>">
    
    <?php the_post_thumbnail(); ?>
    
    <?php the_title(); ?></a></li>
    		<?php endwhile; ?>
    </ul>

    All this does is return all the line items with class "current_page_item" ... I figured that's something to do with the new loop? Barg.

    I'm sure I'm doing something stupid wrong, or I've made this way too complicated. I'm fairly new at this kind of stuff ...

    Thanks for any help.

  2. juri003
    Member
    Posted 4 years ago #

    Hey Moolio,

    It's allready a month ago but did you find a solution? I have the same desire using only post-tuhmbnails.

    Thanks

  3. juri003
    Member
    Posted 4 years ago #

    Ha!

    Made it work.

    <ul>
      		<?php
    
                $args = array(
                    'post_type' => page,
                    'post_parent' => $post->ID,
     				'order' => ASC
               );
                query_posts($args);
    
    if ( has_post_thumbnail() ) {
    
    	} else {
    
    }
                 while (have_posts()) : the_post(); ?>
    
                      <li <?php if (is_page($post->ID)) { echo'class="current_page_item"'; } ?> id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_post_thumbnail(); ?></a></li>
                    <?php endwhile; ?>
    
                    </ul>

    For anybody with the same request

  4. moolio
    Member
    Posted 4 years ago #

    Thanks juri003.

    I'll give it a shot!

    werd.
    m.

Topic Closed

This topic has been closed to new replies.

About this Topic