WordPress.org

Forums

Custom page template. How to check if page is a subpage. (3 posts)

  1. UncleCali
    Member
    Posted 3 years ago #

    Hi. I have a custom page template and a custom post type (authors). This is my page template that queries that post type

    <?php $authors=new WP_Query('post_type=author&order=asc&posts_per_page=999'); ?>
                    <?php if($authors->have_posts()): ?>
                        <ul id="authors-sandbox">
                        <?php while($authors->have_posts()): $authors->the_post(); ?>
                        <?php
                            $skills = get_post_meta(get_the_ID(),'author-skill',true);
                            $author_type = get_post_meta(get_the_ID(),'author-type',true);
                            $yr = get_post_meta(get_the_ID(),'competition-year',true);
    						if(isset($_POST['btn-sort'])){
    							if(!empty($_POST['author-type']) && empty($_POST['author-yr'])){
    								if($author_type != $_POST['author-type'] ) continue;
    							}
    							elseif(!empty($_POST['author-yr']) && empty($_POST['author-type'])){
    								if($yr != $_POST['author-yr'] ) continue;
    							}
    							elseif(!empty($_POST['author-yr']) && !empty($_POST['author-type'])){
    								if($yr != $_POST['author-yr'] || $author_type != $_POST['author-type']) continue;
    							}
    						}
    						elseif(!empty($_GET['letter']) && !isset($_POST['btn-sort'])){
    							$name = get_the_title(get_the_ID());
    							$name = explode(" ",$name);
    							if($name[1][0] != $_GET['letter']) continue;
    
    						}
    						elseif(empty($_GET['letter']) && !isset($_POST['btn-sort'])){
    							if($yr != "2011" || $author_type != "Winner"){
    								continue;
    							}
    
    						}
    
                        ?>
                        <li class="<?php echo $author_type ?> alpha-<?php echo substr(get_the_title(),0,1)  ?> yr-<?php echo $yr; ?> ">
                            <a class="author_anchor" href="<?php the_permalink(); ?>">
    						<?php the_post_thumbnail('author-thumb') ?><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><p><?php echo $skills; ?></p>
                            </a>
                        </li>
                        <?php endwhile; ?>
                        </ul>
                    <?php endif; wp_reset_postdata(); ?>
    
                </article>
                <?php get_sidebar(); ?>
                <div class="clearfix"></div>
                </div>
        </div>
    <?php get_footer(); ?>

    How can I check if the page being called is a subpage?

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    Check for $post->post_parent?

  3. UncleCali
    Member
    Posted 3 years ago #

    Yes. I know its called with if ( is_page() && $post->post_parent )
    but how can I call it in this query? Or should I make a new query?

Topic Closed

This topic has been closed to new replies.

About this Topic