Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

What I want to do is to dislay a description of a country if one of the categories is a country name.

It do it like that

    <?php
if(in_category('afghanistan')) {
    $recent = new WP_Query("page_id=25"); while($recent->have_posts()) : $recent->the_post();?>
        <h3><?php the_title(); ?></h3>
        <?php the_content(); ?>
    <?php endwhile;
}

elseif(in_category('albania')) {
    $recent = new WP_Query("page_id=26"); while($recent->have_posts()) : $recent->the_post();?>
        <h3><?php the_title(); ?></h3>
        <?php the_content(); ?>
    <?php endwhile;
}

else {
    echo "Error!";
}
?>

I would like to replace page_id=25 with pagename=afghanistan. Iif I do so it works well, but if page "afghanistan" is a child of a page "Asia" it doesn't display it anymore. If I use page_id it works, but pagename stops working as soon as I create page as a child of another page. How do I get the page by name if it has a parent? :)

share|improve this question

1 Answer 1

up vote 0 down vote accepted

When you give a page a parent, the slug of the page becomes %parent-pagename%/%pagename%, so you should be able to target it with pagename=asia/afghanistan.

share|improve this answer
    
Thanks a lot! Easy fix, but hard to find –  Tomas Mar 2 '12 at 17:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.