开发者

Wordpress page heirachy is forgotten when I change posts' page

Good day. In WordPress via Settings -> Reading, I updated the page my 开发者_如何学运维posts get output (see screen shot). New page is called Blog. It's parent page is News.

Posts are displaying fine, however, for the Blog page, is_home() is now true!?!. It's URL is unchanged (/news/blog).

A little background: Under the hood I sniff each page to determine what sub nav to display. Since the posts page thinks it's the home page, no sub nav is output, which is not correct.

Why it would lose it's true parent and think that it's the home page now? Is this by design? Any way around this?

WordPress version:3.1 / Theme: Starkers

Thanks.

Wordpress page heirachy is forgotten when I change posts' page


This behavior is normal and causes a lot of confusion. You can either add a special case to the code for your subnav based on the is_home() conditional, or you can create a custom page template that includes a secondary query using WP_Query to pull in recent posts.

Here is a skeleton for the secondary query:

<?php $secondary_query = new WP_Query(array('post_type' => 'post')); ?>
<?php if($secondary_query->have_posts()): ?>
    <?php while($secondary_query->have_posts()): ?>
        <?php $secondary_query->the_post(); ?>
        <?php // normal query stuff like the_title() and the_content() ?>
<?php endwhile; endif;?>
<?php wp_reset_postdata(); ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜