WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Permalink URL does not match page content. (3 posts)

  1. wes.billman
    Member
    Posted 5 years ago #

    Hello All,

    I'm new to WP (moving from drupal) and I'm trying to build a new theme. Things are going very well (so easy with WP), but I have ran into a snag. I started from a blank theme and follow some documentation and examples to build a new theme. Long story short the theme is looking how I want, but when I click on a link to a single post I get a bunch of posts.

    I have something like a recent posts list that just shows recent post from a certain category. When I click on one of the items in that list the URL matches the post that I want to see, but when I run "The Loop" on the index.php I get multiple posts.

    Site can be viewed here. http://lightofdaystudios.com/wp/
    Try clicking on a link in the sidebar to see the issue.

    <?php
    get_header();
    get_sidebar();
    ?>
    
    <div class="content">
    
    	<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    	<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    
    	<?php the_content(); ?>
    
    	<?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?> | <?php the_category(', '); ?> | <?php comments_number('No comment', '1 comment', '% comments'); ?>
    
    	<?php endwhile; else: ?>
    
    	<h2>Woops...</h2>
    
    	Sorry, no posts we're found.
    
    	<?php endif; ?>
    
    	<p align="center"><?php posts_nav_link(); ?>
    
    </div>
    
    <?php
    get_footer();
    ?>
    <div class="sidebar">
    	<div id="latest_tracks" class="box">
    		<h2>LATEST TRACKS</h2>
    		<ul>
    			<?php query_posts('category_name=song&showposts=3'); ?>
      			<?php while (have_posts()) : the_post(); ?>
        		<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php echo the_title(); ?></a><span><?php echo get("artist", 0, 0, false); ?></span></li>
      			<?php endwhile;?>
    		</ul>
    	</div>
    
    	<div id="new_gear" class="box">
    		<h2>NEW GEAR</h2>
    		<ul>
    		<?php query_posts('category_name=Studio&showposts=5'); ?>
    		<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    		<li><a href="<?php echo get("link", 0, 0, false); ?>"><?php the_title(); ?></a></li>
    		<?php endwhile; else: ?>
    		<h2>Woops...</h2>
    		Sorry, no posts we're found.
    
    		<?php endif; ?>
    		</ul>
    	</div>
    
    	<div id="whats_happenin" class="box">
    		<h2>WHAT'S HAPPENIN'</h2>
    		<ul>
    		<?php query_posts('category_name=News&showposts=5'); ?>
    		<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    		<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php echo the_title(); ?></a></li>
    		<?php endwhile; else: ?>
    		<h2>Woops...</h2>
    		Sorry, no posts we're found.
    
    		<?php endif; ?>
    		</ul>
    	</div>
    
    	<div id="people_are_talkin" class="box">
    	<h2>PEOPLE ARE TALKIN'</h2>	<?php query_posts('category_name=Testimonial&orderby=rand&showposts=1'); ?>
    	<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    	<?php echo get("text", 0, 0, false); ?>
    	<span class="source">&mdash;&nbsp;<?php 	if (get("link", 0, 0, false) == "")	{		echo get("source", 0, 0, false);	}	else	{		echo "<a href=\"" . get("link", 0, 0, false) . "\">" . get("source", 0, 0, false). "</a>"; 			}	?>
    	<?php endwhile; else: ?></span>
    	<h2>Woops...</h2>	Sorry, no posts we're found.
    	<?php endif; ?>
    	</div>
    
    	<div id="where_we_is" class="box">
    		<h2>WHERE WE IS</h2>
    		Light of Day Studios is centrally located in Normal Heights off the 805 at Adams Avenue. Get your nifty Google Map here.
    	</div>
    
    </div>

    Thanks for any help!

  2. yoshi
    Member
    Posted 5 years ago #

    query_posts changes the query to the page. And because you called query_posts in the sidebar(and it's before the main Loop), the content is served as if you open a category page.

    To display posts in the sidebar, there is get_posts.

  3. wes.billman
    Member
    Posted 5 years ago #

    yoshi, you're a hero!

    Thanks so much. Guess I miss understood the purpose of the loop a bit.

    Everything is working now.

    Thanks again.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.