WordPress.org

Ready to get started?Download WordPress

Forums

Have a page that shows only one childe category (8 posts)

  1. martcol
    Member
    Posted 3 years ago #

    That's the core of what I need but I also want to exclude the same child category from another page.

    I am using category-name.php templates and I have one category "blog" on category-blog.php; then category-poem.php for poems and now I have one for category-poem-adult.php. That's all fine. I just copied the loop into those pages and it all works.

    Now the problem is that if I click on the "adult" category it uses the correct template but if I click on say, the title, it shows on the category-poem.php template.

    I hope I have explained that OK.

    Thanks

    Martin

  2. martcol
    Member
    Posted 3 years ago #

    I am really stuck on this.

    This is what I have.

    category-blog.php
    category-poem.php

    single.php

    I want a sub category of "poem" i.e. "adult" to show on it's own single page. I don't want that sub category to show on the single page that the other posts use.

    Martin

  3. martcol
    Member
    Posted 3 years ago #

    So this is what I'm trying now in single.php...

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php if ( in_category( '22' )); {?>
    <h5>Try this out</h5>
    <?php } ?>
    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <?php if (is_single()) { ?><h1><?php the_title(); ?></h1>

    I'm thinking that should just bang out my <h5>Title</h5> on every page that shows a post with category 22.

    Sadly, I'm wrong (again) and it shows up on every post in single.php.

  4. martcol
    Member
    Posted 3 years ago #

    OK; so now I'm failing with the last one and trying this out. It's explained on lorelle.wordpress.com and involves replacing the whole of single.php with:

    <?php
    $post = $wp_query->post;
    if ( in_category('8') ) {include(TEMPLATEPATH . '/single-poem.php');}
    elseif ( in_category('22') ) {include(TEMPLATEPATH . '/single-adult.php');}
    else {include(TEMPLATEPATH . '/single-blog.phpp');}
    ?>

    This one makes sense to me but, I am gettin the worse result ever.

    thanks

  5. martcol
    Member
    Posted 3 years ago #

    <?php
    $post = $wp_query->post;
    if ( in_category('8')) {
    include(STYLESHEETPATH . '/single-poem.php');
    } elseif ( in_category('22')) {
    include(STYLESHEETPATH . '/single-adult.php');
    } else {
    include(STYLESHEETPATH . '/single-blog.php');
     }
     ?>

    Well that's the next incarnation. I found out that TEMPLATEPATH isn't good in a child theme.

    My problem is now that category 22 is a child of category 8 so it still won't work. So really, I am back to SqOne! I'm doing all this because I want to add some unique content to the adult single pages.

  6. martcol
    Member
    Posted 3 years ago #

    Well, I'm persisting with this but still no luck

    <?php
    $post = $wp_query->post;
    if (in_category( 8 )) {
    include(STYLESHEETPATH . '/single02.php');
    } elseif (in_category( 23 )) {
    include(STYLESHEETPATH . '/single03.php');
    } else {
    include(STYLESHEETPATH . '/single01.php');
    }
    ?>

    My child category (23) is a sub-cat of (8). This only used single02 or single01. I tried it by adding this line:

    if (in_category( 8,-23 )) {

    And that made it default to single03. I thought I had it then, but it also stoppede using single02.php! I guess that's because I did somthing wrong in the code.

  7. martcol
    Member
    Posted 3 years ago #

    Well,

    I think it's sorted now by swithing the checks. I got this nudge from a Sitepoint forum.

    <?php
    $post = $wp_query->post;
    } elseif (in_category( 23 )) {
    include(STYLESHEETPATH . '/single03.php');
    if (in_category( 8 )) {
    include(STYLESHEETPATH . '/single02.php');
    } else {
    include(STYLESHEETPATH . '/single01.php');
    }
    ?>

    If anyone can tell me why that might happen, I would appreciate it.

    Martin

  8. martcol
    Member
    Posted 3 years ago #

    Well, one more thing to say here, just in case it gets any other interest. I think this works because checking for a parent category first will show the template for that category because the child category has both categories. Checking for the child category first means that the required template page will get called before WP has a chance to go for the other one.

    I think that's it.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.