• Resolved hilj

    (@hilj)


    I use WP as CMS, but I have blog there too. I use Pages and Posts to display the website stuff, without the possibility to comment, of course.

    In the blog I would like to have the comments. So I did a new template file blog.php where I show all the comment stuff and called it in the archive.php with an if statement:

    <?php if (is_category('18')) {include(TEMPLATEPATH . '/blog.php');
    	} ?>

    The blog posts appears there like it should, with the comment possibility. But the problem is, the blog posts show in double now, the one with the comments and the one without (the without is hanging there on the side).

    Do I need to exclude the other one somehow?

    Help appreciated. Thanks.

Viewing 10 replies - 1 through 10 (of 10 total)
  • MichaelH

    (@michaelh)

    If possible, please post the contents of your template file (archive.php) at https://wordpress.pastebin.ca/ and report that link back here.

    Thread Starter hilj

    (@hilj)

    Wow, pastebin. I didn’t know such existed.

    Here’s my archive.php

    In line 5 you can see if include thing.

    Thank you.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    You’re doing the if_category thing to include a page, but then after that page is included, the rest of your archive page is also being spit out as well. Think of it like this:

    <?php if (is_category(18)) { show blog.php; } ?>
    Some other stuff here.

    The “some other stuff” will show on both category 18 AND non-category 18 pages.

    What you probably want to do is something more like this:

    <?php if (is_category(18)) { show blog.php; }
    else { ?>
    Some other stuff here.
    <?php } // end of the "else" ?>

    Then the some other stuff only shows up on NON category 18 pages. See?

    Thread Starter hilj

    (@hilj)

    New one is here, is that what you meant?
    Anyway it works! Thank you!

    You’re using the show:
    <?php if (is_category(18)) { show blog.php; }
    I’m using:
    <?php if (is_category('18')) { include(TEMPLATEPATH . '/blog.php'); }

    I tried to use that show, but it didn’t work?

    Thak you for this.

    Thread Starter hilj

    (@hilj)

    I just came up with another problem. The single post pages for my blog posts. Of course I took all the comment related stuff away from the single.php cause I was using Posts to display normal website stuff.

    What conditions should I use here to guide the single posts to be viewed according to say, single_blog.php template file?

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    I was just using pseudo-code, I didn’t mean for the “show” to be taken literally. ??

    As for the single posts thing, you’re basically wanting to tell if the given post is in category 18, correct?

    This code will pull the category information for a post and then include single_blog if the post is in category 18:

    <?php if (is_single()) {
    $post = $wp_query->post;
    if (in_category(18)) {
    include(TEMPLATEPATH . '/single_blog.php'); }
    else {
    // rest of page goes here
    }
    } // end if is_single
    ?>
    Thread Starter hilj

    (@hilj)

    Thank for this. It partly works.

    If I just put the whole upper mentioned code to the beginning of my single.php, it uses the single_blog.php like it should, but it shows, of course, in double.

    If I try to use the else, to get rid of the double, it’s not working, nothing shows.

    This code (lines, 5-13) shows the single_blog.php like it should, but in double.

    Here, (lines, 5-9 and 37-39) when I use the else nothing shows.

    This is kind of a complicated to such beginner as me, i’m getting there ?? Thanks.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    No, no, you’re supposed to put the rest of the page where I said “// rest of page goes here”. Like this:

    https://wordpress.pastebin.ca/798998

    None of this code is cut and paste, this is all custom work. You will have to make any solution we give you fit your specific circumstances. We don’t have any idea what your page looks like, all we can do is give you concepts and ideas and try to show you how the thing works. We can’t give you exactly correct answers.

    If you don’t understand PHP and/or programming in general, you probably should read up on that before attempting to do any of this yourself. It’s not difficult, but it does require a general understanding of the subject.

    Thread Starter hilj

    (@hilj)

    I first did that, in the second example:

    Here, (lines, 5-9 and 37-39) when I use the else nothing shows.

    I was just trying to wonder and ponder that what’s wrong with it, cause it’s not working, just plank page appears.

    Then I tried to mess with it a to pin point the flaw. Obviously the flaw is not in the if statement but in the else statement.

    I’m reading about php all the time. For example here w3schools.com But just reading is not helping much (at least for me), by doing is better and that’s just what I’m doing here, with your generour help ??

    Thread Starter hilj

    (@hilj)

    Okay I got it! It works just fine. Thank you for your help! ??

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Understading conditional tags?’ is closed to new replies.