• Resolved cjbee

    (@cjbee)


    Long time lurker, first time poster. 🙂

    On my single post (single.php) page, I am using a tag in the template which displays a titled list of other news items (for navigational purposes):

    <?php get_archives('postbypost', '6', 'html', '', '', FALSE); ?>

    This is all fine and dandy…but I’m looking for a way to exclude the title of the post that is currently being viewed from the list. Any ideas?

    Hopefully this makes sense, heh. Here’s a screenshot that attempts to explain what I mean:

    http://thirtylivegroup.com/images/screenshot.jpg

    Thanks in advance.

Viewing 15 replies - 1 through 15 (of 17 total)
  • mheltone

    (@mheltone)

    Post your single.php here.
    Let me take a look at it.

    Are you using a widget on your sidebar for the other news?

    Thread Starter cjbee

    (@cjbee)

    Nope — not using any sidebar or widget on this page. The “other news” is just listed in a div that I added within the template:

    <?php get_header(); ?>
    <div id="page">
        <div id="page-inner" class="clearfix">
            <div id="othernews">
                <div class="box">
                    <h3>Other News</h3>
                   <ul><?php get_archives('postbypost', '6', 'html', '', '', FALSE); ?></ul>
                </div>
            </div>
            <div id="content">
                <?php if(have_posts()) : ?><?php while(have_posts())  : the_post(); ?>
                <div id="post-<?php the_ID(); ?>" class="post-content clearfix">
                    <h3 class="entry-title"><?php the_title(); ?></h3>
                    <?php include (TEMPLATEPATH . '/includes/postmeta.php'); ?>
                    <?php if (has_post_thumbnail()) {
                    $thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'thumbnail_name');
                    ?><a>" rel="shadowbox"><img class="postimg" src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo $thumb[0]; ?>&zc=1&w=625&h=400&q=100&a=c" alt="<?php
                    the_title(); ?>" /></a>
                    <?php } ?>
                    <div class="entry clearfix">
                        <?php the_content(); ?>
                        <?php wp_reset_query(); ?>
                        <!-- <?php trackback_rdf(); ?> -->
                        <p><a href="history.go(-1)"><span class="arrow_back">Back</span></a></p><div class="divider"></div>
                    </div>
                    <div id="comments">
                        <?php comments_template(); ?>
                    </div>
                </div>
                <?php endwhile; ?>
                <?php else : ?>
                <?php endif; ?>
            </div>
            <?php get_footer(); ?>

    mheltone

    (@mheltone)

    Probably best If I can actually see your website.
    And also the codes on your OTHER NEWS.

    Thread Starter cjbee

    (@cjbee)

    Here’s a link to a single post:

    http://www.thirtylivegroup.com/2011/02/30live-group-feature-band-aardvark-robinson/

    *Note: The “outernews” div referenced in the code I posted above was changed for clarity…on the actual site, that div is actually called “sidebar”.

    mheltone

    (@mheltone)

    Let’s start on your sidebar.
    You can remove that by adding this code to your LOOP.

    if( $post->ID == '112' ) continue;

    Replace the 112 with the POST ID of that post.

    Example:
    <?php while (have_posts()) : the_post(); if( $post->ID == '112' ) continue; ?>

    Try that.

    Thread Starter cjbee

    (@cjbee)

    Thanks, but it didn’t seem to do anything. 🙁

    mheltone

    (@mheltone)

    Let me see your sidebar codes.

    Thread Starter cjbee

    (@cjbee)

    That sidebar isn’t actually a sidebar…as in, not dynamic. I basically hard-coded the “other news” box within the XHTML, if that makes any difference.

    The code I’m using is essentially what I listed above:

    <div id="othernews">
                <div class="box">
                    <h3>Other News</h3>
                   <ul><?php get_archives('postbypost', '6', 'html', '', '', FALSE); ?></ul>
                </div>
            </div>

    That’s all I’m using to display that list of other posts.

    mheltone

    (@mheltone)

    <div id="othernews">
                <div class="box">
                    <h3>Other News</h3>
    			<ul>
    			<?php query_posts('posts_per_page=6'); ?>
    			<?php if (have_posts()) : while (have_posts()) : the_post(); if( $post->ID == '117' ) continue; ?>
                   <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
    			<?php endwhile; ?><?php endif; ?>
    			<?php wp_reset_query(); ?>
    			</ul>
                </div>
            </div>

    Try this code.
    And please edit the 117 for the POST ID of that POST.

    Thread Starter cjbee

    (@cjbee)

    Yes! That works brilliantly. Thanks so much. But…

    What would I have to add if I want the POST ID in that code to reflect the POST ID of whatever post is currently being viewed?

    mheltone

    (@mheltone)

    Hang-on Let me test it on my server first.

    Thread Starter cjbee

    (@cjbee)

    No problem.

    Thanks again for all your help.

    mheltone

    (@mheltone)

    <div id="othernews">
                <div class="box">
                    <h3>Other News</h3>
    			<ul>
    			<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    			<?php $filteredid = the_ID(); ?>
    			<?php endwhile; ?><?php endif; ?>
    			<?php query_posts('posts_per_page=6'); ?>
    			<?php if (have_posts()) : while (have_posts()) : the_post(); if( $post->ID == '$filteredid' ) continue; ?>
                   <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
    			<?php endwhile; ?><?php endif; ?>
    			<?php wp_reset_query(); ?>
    			</ul>
                </div>
            </div>

    Try this.. I hope this works.

    Thread Starter cjbee

    (@cjbee)

    All it seems to be doing is spitting out the ID of the post at the top of the list:

    http://www.thirtylivegroup.com/images/screenshot2.jpg

    I see where you were going with it though…

    mheltone

    (@mheltone)

    Ok.. Try this..

    <div id="othernews">
                <div class="box">
                    <h3>Other News</h3>
    			<ul>
    			<?php if (have_posts()) : while (have_posts()) : the_post(); $nodup = $post->ID; ?>
    			<?php endwhile; ?><?php endif; ?>
    			<?php query_posts('posts_per_page=6'); ?>
    			<?php if (have_posts()) : while (have_posts()) : the_post(); if( $post->ID == $nodup ) continue; ?>
                   <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
    			<?php endwhile; ?><?php endif; ?>
    			<?php wp_reset_query(); ?>
    			</ul>
                </div>
            </div>
Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Exclude an item from a list of news items…’ is closed to new replies.