• Hi guys,

    So I have my home page on my site which displays all the post titles in a list:
    |———————-|
    |–post title 1——–|
    |–post title 2 etc—-|
    |———————-|
    On my single.php page -> lets say you click on post 1, I want the following layout:

    |—————|————————–|
    |- post title 1 | POST TITLE 1————-|
    |- post title 2 | “Post title one content” |
    |—————|————————–|
    So for the home page I have this code which displays the 5 newest titles:

    <?php
       query_posts('showposts=5');
    ?>
    
    <?php if (have_posts()) : ?>
    <h2 id="broadcast">Broadcast.</h2>
     <ul id="broadcast">
     <?php while (have_posts()) : the_post(); ?>
    	<li id="broadcast">
    	<a href="<?php the_permalink(); ?>"><?php the_title(); ?>.</a>
    	</li>
    <?php endwhile; ?>
    </ul>
    <?php endif; ?>

    So I copied and pasted this into the single page, but now instead of just displaying one news story, it displays all the stories!! This is the code I have:

    <div id="news_menu_left">
    <?php
       query_posts('showposts=100');
    ?>
    <?php if (have_posts()) : ?>
    <ul id="news_left_titles">
     <?php while (have_posts()) : the_post(); ?>
    	<li id="news_left_titles">
    	<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    	</li>
    <?php endwhile; ?>
    </ul>
    <?php endif; ?>
    </div>
    
    <div id="news_container_single">
    	<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
    
    		<div class="post" id="post-<?php the_ID(); ?>">
    
    			<h2 id="news_page_title"><?php the_title(); ?>.</h2>
    
    			<div class="entry">
                	<div class="post_content">
    
    				<?php the_content(); ?>
    
                    </div>
    
                    <p class="postmetadata">
    				<?php the_time('l, F jS, Y') ?><?php _e(' | Share on Facebook'); ?> <br />
    				</p>
    
    			</div>
    			<div id="comments-template">
    			<?php comments_template(); ?>
    			</div>
    		</div>
    
    	<?php endwhile; ?>
    
    		<div class="navigation">
    			<?php posts_nav_link(); ?>
    		</div>
    
    	<?php else : ?>
    
    		<div class="post">
    			<h2><?php _e('Not Found'); ?></h2>
    		</div>
    
    	<?php endif; ?>
    
    </div>

    So from the above code, the div “new_menu_left” should display the list of 100 news titles down the left, and then the div “news_container_single” should show the one news story selected from the home page and it’s content. I know I’m nearly there,
    PLEASE PLEASE CAN SOMEONE HELP!!!!

Viewing 12 replies - 1 through 12 (of 12 total)
  • try adding this <?php query_posts('posts_per_page=1'); ?> right below
    <div id="news_container_single">

    Thread Starter john_london

    (@john_london)

    Mmmm thanks, but that displays one news story but only the first one – it doesn’t change which ever post title I click on – always the same post title on the single page?

    Thread Starter john_london

    (@john_london)

    So basically this is what I’m trying to get:

    index.php
    a list of the most recent 5 post titles [done]

    single.php
    a list of the most recent 5 post titles (left side div)

    the selected post title and its content (main div) with comments

    what do you mean by selected post title?
    like when you click the title you get the post?

    Thread Starter john_london

    (@john_london)

    Hey Gbaka – thanks for the quick reply. Yes, I think so – I’ll use an example to clarify:

    Index.php
    Post Title 1: T-Shirt Giveaway
    Post Title 2: We have a gig tomorow night
    Post Title 3: New single out today

    So you click on Post 1, which takes you to:

    Single.php

    Left div: displays the post titles as with index.php

    Main div:
    Post Title 1: T-shirt Giveaway
    Post 1 Content: Hey guys, we’re giving away free t-shirts so come and get one …etc
    Post 1 Comments, etc

    <?php $recent = new WP_Query("showposts=10"); while($recent->have_posts()) : $recent->the_post();?> use this code instead of the query post

    Thread Starter john_london

    (@john_london)

    Hi gbaka – I apologise for my stupidity and thank you again – but which code does this replace? I’ve tried a few variations but each time leads to a completely blank page!

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

    and get rid of the end while and end if codes just below it

    Thread Starter john_london

    (@john_london)

    <div id="news_menu_left">
    <?php $recent = new WP_Query('showposts=10');
    while($recent->have_posts()) : $recent->the_post();?> 
    
    <?php if (have_posts()) : ?>
    <ul id="news_left_titles">
     <?php while (have_posts()) : the_post(); ?>
     <div class="news_menu_item">
    	<li id="news_left_titles">
    	<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    	</li>
      </div>
    <div id="archives">
    <h4>MP NEWS ARCHIVES</h4>
    <select name="archive-dropdown" onChange='document.location.href=this.options[this.selectedIndex].value;'>
      <option value=""><?php echo attribute_escape(__('Select Month')); ?></option>
      <?php wp_get_archives('type=monthly&format=option&show_post_count=1'); ?> </select>
    
    </div>
    </div>

    Is this right? I keep getting a white screen!! Sorry!!

    you were only suppose to get rid of the first endwhile and endif, the white screen might be becuase you got rid of them all

    <div id="news_menu_left">
    <?php $recent = new WP_Query("showposts=10"); while($recent->have_posts()) : $recent->the_post();?>
    
    <ul id="news_left_titles">
    
    	<li id="news_left_titles">
    	<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    	</li>
    <?php endwhile; ?>
    </ul>
    
    </div>

    use this to replace your first div from your original code

    Thread Starter john_london

    (@john_london)

    OH MY GOD IT’S WORKED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Thank you SO much for your time gbaka – it’s amazing that you help people like me – I hope something really pleasant happens to you tomorow like you win the lottery or something. Bless

    x

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Displaying post titles on single news story page’ is closed to new replies.