• jinsan

    (@jinsan)


    simple question really – I only want posts from cat a to b to show on index.php. Where in the loop do I make the edits so that those cats remain hidden, until another page is clicked?

    I want to do this without creating a page or using a plugin if possible. I know about Ryan’s plugin and a few others, but they seem to involve pages, and I think there’ s asolution using the loop like if category x, exclude, else display.

    I found this link:

    http://codex.wordpress.org/The_Loop#Exclude_Posts_From_Some_Category

    But the examples confuse the hell out of me, and the <!--> just make things really messy to understand. I want to apply this to more than one cat, so would the result be:

    <?php if ( !(in_category('3,4,5')) ) { ?> to exlcude cats 3-5?

    Cheers

Viewing 6 replies - 1 through 6 (of 6 total)
  • neetij

    (@neetij)

    I don’t know for sure, but I think the in_category function only accepts one category as argument.

    So, your code could be:
    <?php if ( !in_category('3') || !in_category('4') || !in_category('5') { ?>
    //rest of code
    <?php } ?>

    Then further on, in another area you would have code like this:
    <?php rewind_posts(); ?>
    <?php query_posts('category_name=asides&showposts=10'); ?>
    <?php while (have_posts()) : the_post(); ?>
    \rest of code
    <?php endwhile;?>

    I have a similar setup (only one category) in the theme I’m working on – two examples. I don’t want my ‘Asides’ category posts to show as a post on main pages, but I want it visible in archive pages.

    (I’m not terrible experienced with php or wordpress code, so there’s my disclaimer. 🙂

    Thread Starter jinsan

    (@jinsan)

    Hmm well that gives me a start I guess, I have no expereince, so you’re one up on me. I emailed ifelse and he suggested this:

    <?php if (!(in_category('11')&&in_category('12')&&in_category('13')&&in_category('14'))){
    the_content();}?>

    The problem I’m finding is where to place the code. The top of the code php file is this:

    <?php get_header();
    if ($posts) { $pcount_lp = sizeof($posts); foreach ($posts as $post) {start_wp();?>

    Do I place it in that or after?

    And whereabouts would I place the second part of the code? I’m playing with it, but if I have some idea of where it should be placed between x and y for example, it would help me a ton. I very much appreciate the reply though.

    Having tried the above: <?php if ( !in_category('11') || !in_category('12') || !in_category('13') || !in_category('14') { ?>
    //rest of code
    <?php } ?>

    It gives me:

    Parse error: parse error, unexpected '{' in /home/jinsan/public_html/wp/wp-content/themes/gespaa/index.php on line 4

    Line 4 being that part of the code. I placed it after the get header. I don’t use asides btw

    neetij

    (@neetij)

    Put the code in the index.php file (Main Template). I think ifelse’s code version is correct if you want to exclude posts that are in all three categories. Using ‘or’ (||) it will exclude posts that fall in any one of the categories.

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    \ your if else code
    \ mine: <?php if (is_home() && in_category('27') ) { ?>

    I’m not familiar with the gespaa theme, but it should be after you’ve begun the while loop.

    Thread Starter jinsan

    (@jinsan)

    bugger, I don’t actually have the while part of the loop. It still provides the unexpected { error.

    I don’t want to replace the start of the template with the <?php if (have_posts()):?> in case it breaks the site – mind you it keep sbreaking anyway so maybe I should try. Here’s the template for the index.php:


    <?php
    get_header();
    if ($posts) { $pcount_lp = sizeof($posts); foreach ($posts as $post) {start_wp();?>
    <div class="entry">
    <div class="catimage">
    <?php c2c_the_category_image($seperator='', $parents='',
    $image_extensions='png gif jpg',
    $image_dir='/wp-content/images/',
    $use_name_if_no_image=false); ?>

    </div>

    <?php
    the_date('','<h3 class="entrytitle">','</h3>');
    ?>
    <h2 class="entrydate" id="post-<?php the_ID(); ?>"><a href="<?php echo get_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    <h3 class="entrytitle"><strong><?php _e("Filed under:"); ?> <?php the_category(' and') ?> </strong></h3>
    <div class="entrybody"><strong><?php the_author() ?> wrote this <?php the_time(); ?>:</strong>
    <?php if (!(in_category('11')&&in_category('12')&&in_category('13')&&in_category('14'))){the_content();?></div>
    <?php }?>
    <p class="comments_link">
    <?php
    $comments_img_link = '<img src="' . get_stylesheet_directory_uri() . '/images/comments.gif" title="comments" alt="*" />';
    comments_popup_link('No Comments', $comments_img_link . ' 1 Comment', $comments_img_link . ' % Comments');
    ?>
    </p>

    <?php
    if ($pcount_lp == 1){
    comments_template();
    } ?>
    <?php }?>
    <div class="prev_next_nav">
    <?php posts_nav_link('','','&laquo; Previous Entries'); ?> &nbsp; &nbsp; <?php posts_nav_link('','Next Entries &raquo;',''); ?>
    </div>
    <?php } else { // end foreach, end if any posts ?>
    <div class="entrybody"><p>Sorry, no posts matched your criteria.</p></div>
    <?php } ?>

    <?php get_footer(); ?>

    It’s not longer causing php errors but it’s not excluding the categories either.

    oriecat

    (@oriecat)

    I use the Front Page Categories plug in and it works really well and easily. It doesn’t involve Pages, maybe you are misunderstanding because of the title. It doesn’t make a new Front Page, it just modifies index.php to only include the cats you tell it to.

    Thread Starter jinsan

    (@jinsan)

    hmmm well, when a plugin is called Front Page it sort of makes you think front Page, yer know? There has to be another word for what is called Pages and pagers – I mean it’s pretty confusing! So let’s think….how about paper? Naw…

    Ok I;m going to look into that Front Page plugin if you’re sure it’s not just about pages, because that is exactly what I thought you thought I was thinking. And it excludes cats right? Cheers

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘how to exclude cats without creating a front page’ is closed to new replies.