• Resolved cyberico

    (@cyberico)


    hi
    hope you can help me. this is the code to show the LATEST post (using all categories and all the posts).

    i want the latest post, BUT excluding posts from a specific category (ie ID=3).

    please help me change the code:

    ________________________
    <h3 class=”sec-title”>Latest Article</h3>
    <div class=”post” id=”post-<?php the_ID(); ?>”>

    <?php
    $posts = get_posts(‘numberposts=1’);
    foreach($posts as $post) :
    setup_postdata($post);
    ?>
    <h2 class=”post-title”>” title=”Permanent link to <?php the_title(); ?>”><?php the_title(); ?></h2>
    <p class=”post-meta”><?php the_time(‘F jS, Y’) ?> / <?php the_category(‘, ‘) ?> / <?php comments_popup_link(‘No comments’, ‘1 comment’, ‘% comments’,’Comments are off for this post’); ?>
    <div class=”post-body”>
    <?php the_excerpt(); ?>
    <p class=”more”>” title=”Permanent link to <?php the_title(); ?>”>Continue reading
    </div>
    </div>
    <?php endforeach; ?>
    _________________

    thnx
    enrico

Viewing 9 replies - 1 through 9 (of 9 total)
  • Will something in here, maybe help too? I’m *not sure*, but, just was throwing this out.. =P
    https://www.ads-software.com/support/topic/70943?replies=9

    spencerp

    Good call, Spencerp. The category visibility plugin simplifies things a bit https://ryowebsite.com/?p=46

    Hehe, no problem. =) “Were” a part of that “awesome” groupie clique right.. were just supposed to be “awesome”.. haha..nah, just kidding. =P

    spencerp

    Thread Starter cyberico

    (@cyberico)

    no query_posts does not work because the code that uses my template (Brajeshwar v7.0) seems to be a “revised loop”.

    see:
    https://codex.www.ads-software.com/Displaying_Posts_Using_a_Custom_Select_Query

    i need another command line to exclude a category that works with it.

    any idea??

    Thread Starter cyberico

    (@cyberico)

    hi

    i found another way that now excludes a choosen category (i.e. #6).

    but the problem now is that im no more able to display the very latest post.

    is anybody able to fix my code? i think the fixed code will make happy lot of wordpress users.

    _________

    <h3 class=”sec-title”>Latest Article</h3>

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php if ( !(in_category(‘6’)) ) { ?>

    <div class=”post”>

    <h2 class=”post-title”>” title=”Permanent link to <?php the_title(); ?>”><?php the_title(); ?></h2>
    <p class=”post-meta”><?php the_time(‘F jS, Y’) ?> / <?php the_category(‘, ‘) ?> / <?php comments_popup_link(‘No comments’, ‘1 comment’, ‘% comments’,’Comments are off for this post’); ?>
    <div class=”post-body”>
    <?php the_excerpt(); ?>
    <p class=”more”>” title=”Permanent link to <?php the_title(); ?>”>Continue reading
    </div>
    </div>

    <?php } ?> <!– Close the if statement. –>
    <?php endwhile; else: ?>
    Sorry, no posts matched your criteria.
    <?php endif; ?>

    ____________________

    thnx
    enrico

    Thread Starter cyberico

    (@cyberico)

    This CODE works good for me in wordpress 2.0 to accomplish this purpose:

    a) to display the LATEST post in excerpt fashion (ideal in the frontpage)

    b) to EXCLUDE a specific category (i.e. #6) that will not be eligible for latest post

    here the code:

    <h3>Latest Article</h3>

    <?php query_posts('showposts=1'); ?>

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php if ( !(in_category('6')) ) { ?>

    <div class="post">
    <h2 class="post-title"><a>" title="Permanent link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    <p class="post-meta"><?php the_time('F jS, Y') ?> / <?php the_category(', ') ?> / <?php comments_popup_link('No comments', '1 comment', '% comments','Comments are off for this post'); ?>
    <div class="post-body">
    <?php the_excerpt(); ?>
    <p class="more"><a>" title="Permanent link to <?php the_title(); ?>">Continue reading</a>
    </div>
    </div>

    <?php } ?> <!-- Close the if statement. -->

    <?php endwhile; else: ?>
    Sorry, no posts matched your criteria.
    <?php endif; ?>

    Code will find the latest post excluding category #6.

    you can change category ID/number modifing this line (change number 6):

    <?php if ( !(in_category('6')) ) { ?>

    you can display the 2 or 3 or .. last posts modifing this line (change number 1):

    <?php query_posts('showposts=1'); ?>

    good luck!
    enrico

    <?php if ( !(in_category(’14’)) ) { ?>

    The statement above seems to have no effect on my loop! I’m trying to hide category 14 from my front page and do a small asides section to show cat 14 above the loop in another mini loop.

    I’ve cut and paste that exact same piece of code only to find it doesn’t exclude the posts. I really don’t know why. I’m using the scarylittle theme found here

    https://scarylittlemonkey.com/go/scary-little-theme-is-official-mostly/

    From what i know it shouldn’t affect the php at all. This is how he implements his loop

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <?php if ( !(in_category(’14’)) ) { ?>

    <div class=”blog”><div class=”blog2″><div class=”blog3″>

    <div class=”date”><div class=”dateblock”>
    <div class=”month”><?php the_time(‘F’); ?></div>
    <div class=”day”><?php the_time(‘j’); ?></div>
    <div class=”year”><?php the_time(‘Y’); ?></div>
    <div class=”month”><?php the_time(‘g:i a’); ?></div>
    </div>

    <div class=”cathead”>Tags:</div>
    <div class=”cats”>
    <?php the_category(‘
    ‘); ?>
    </div>

    <div class=”cathead”>Post Meta :</div>
    <div class=”cats”>
    ” title=”Trackback this post”>Trackback
    ” title=”The Permalink”>Permalink
    <?php edit_post_link(‘Edit’, ”, ”); ?>
    </div>

    </div>

    <div class=”text”>

    <div class=”title”>

    ” rel=”bookmark” title=”Permanent Link: <?php the_title(); ?>”>
    <?php the_title(); ?>

    </div>

    <div class=”entry”>
    <?php the_content(); ?>
    </div>
    </div>
    <div class=”clear”></div>
    <div class=”commentlink”><?php comments_popup_link(__(‘No Comments.’), __(‘One Comment.’), __(‘% Comments.’)); ?></div>
    <div class=”clear”></div>
    </div></div></div>

    <?php comments_template(); // Get wp-comments.php template ?>

    <?php } ?>
    <?php endwhile; else: ?>

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘latest post excluding a specific category’ is closed to new replies.