WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: WP-PageNavi] Paginate all posts on single.php page (9 posts)

  1. azenalex
    Member
    Posted 4 years ago #

    Using the latest WordPress and WP-PageNavi. The plugin works great on the index and archive pages but when I try to use it on the single page it ends up appending the paging arguments to the end of the single post url (eg. http://domain/2010/03/02/post-name/page/2/) which results in the same page getting loaded.

    Just to be clear what i'm trying to do here is show a single post and then list all the posts below it (the same as is shown on the index page). Going to the second page should again load the same single post but list the second page of the total results. An alternative solution that would be acceptable would be for paging to just act as if a page button was hit on the index page (eg. route to http://domain/page/2/).

    Any help on how to get the behavior I need would be great. Thank you and I've put code snippets from single.php below.

    <?php get_header(); ?>
    	<!-- content -->
    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    		<!-- post -->
    		<div class="videobox" id="post-<?php the_ID(); ?>">
    			<div class="left">
    				<div class="videopanel">
    					<div class="title">
    						<h1><?php the_title(); ?></h1>
    					</div>
    					<div class="contentbody">
    						<center>
    						<?php $video_code = thman_getcustomfield('video_code',get_the_ID()); if(!empty($video_code)) : ?><center><div class="video_code"><?php echo $video_code; ?></div></center><?php endif; ?>
    						</center>
    					</div>
    				</div>
    			</div>
    			<div class="right">
    				<div class="panel">
    <center>
    </center>
    				</div>
    			</div>
    		</div>
    		<div class="videodesc">
    <table><tr><td>
    			<h1><?php the_title(); ?></h1>
    			<p><?php the_content('Read the rest of this entry &raquo;'); ?></p>
    			<?php $categories = get_the_category(get_the_ID());?>
    			<h2><span>Categories:</span>
    				<?php foreach($categories as $cat):?>
    				<a href="<?php echo get_option('home').'/?cat='.$cat->cat_ID;?>"><?php echo $cat->name;?></a>
    				<?php endforeach;?>
    			</h2>
    			<h2><span>Date Added:</span> <?php the_date();?> at <?php the_time();?></h2>
    			<h2><span>Length:</span> <?php $duration = thman_getcustomfield('duration',get_the_ID()); if(empty($duration)) $duration = '0:00'; echo $duration; ?></h2>
    			<h2><span>Views:</span> <?php if(function_exists('the_views')) the_views();?></h2>
    			<h2><span>Rating:</span><?php if(function_exists('the_ratings')) the_ratings();?></h2>
    </td><td></td></tr></table>
    		</div>
    		<!-- /post -->
    		<?php comments_template(); ?>
    	<?php endwhile; else: ?>
    		<p class="nopost">Sorry, no posts matched your criteria.</p>
    	<?php endif; ?>
    
    	<!-- content -->
    	<?php
    		$wp_query = new WP_Query();
    		$wp_query->query('');
    	?>
    	<div class="panel">
    		<div class="title">
    			<?php //check if title needs to be set
    				$title = 'Posts for Today';
    				if(isset($_GET['r_sortby']) && $_GET['r_sortby']=='highest_rated') $title = 'Highest Rated';
    				if(isset($_GET['v_sortby']) && $_GET['v_sortby']=='views') $title = 'Most Viewed';
    				if(isset($_GET['c_sortby']) && $_GET['c_sortby']=='most_commented') $title = 'Most Commented';
    			?>
    			<h1 class="main_title">My <?php echo $title;?></h1>
    			<h2><?php echo wp_get_todays_post_count();?> New Posts Added Today, <?php echo wp_get_total_post_count();?> Total</h2>
    		</div>
    		<div id="content" class="contentbody">
    			<?php if($wp_query->have_posts()):?>
    				<?php $i=0; while ($wp_query->have_posts()) : $wp_query->the_post(); $i++; ?>
    				<?php if($i%4==1) : ?><div class="update-row"><?php endif; ?>
    					<div class="update-entry">
    						<a class="thumbs" href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php $thumb = thman_getcustomfield('thumb',get_the_ID()); if(!empty($thumb)) : ?>
    							<img src="<?php echo $thumb; ?>" width="240" height="180" border="0" alt="<?php the_title_attribute(); ?>" />
    						<?php else : ?>
    							<img src="<?php bloginfo('template_url'); ?>/images/pic_empty.gif" alt="<?php the_title_attribute(); ?>" />
    						<?php endif; ?></a>
    						<h1><?php echo thman_get_limited_string($post->post_title,15); ?></h1>
    						<h2><?php $duration = thman_getcustomfield('duration',get_the_ID()); if(empty($duration)) $duration = '0:00'; echo $duration; ?> Min | <?php if(function_exists('the_views')) { the_views(); } ?> | <?php comments_number('0', '1', '%'); ?> Comments</h2>
    						<?php if(function_exists('the_ratings')) { ?><div class="update-rating"><?php the_ratings(); ?></div><?php } ?>
    					</div>
    				<?php if($i%4==0) : ?></div><?php endif; ?>
    				<?php endwhile; ?>
    			<?php else:?>
    				<p class="nopost">Sorry, but you are looking for something that isn't here.</p>
    			<?php endif;?>
    			<?php
    			//echo $wp_query->request;
    			$next_page = get_next_posts_link('Previous');
    			$prev_pages = get_previous_posts_link('Next');
    			if(!empty($next_page) || !empty($prev_pages)) :
    			?>
    			<!-- navigation -->
    			<div class="navigation">
    				<?php if(!function_exists('wp_pagenavi')) : ?>
    		        <div class="alignleft"><?php echo $next_page; ?></div>
    				<div class="alignright"><?php echo $prev_pages; ?></div>
    		        <?php else : wp_pagenavi(); endif; ?>
    			</div>
    			<!-- /navigation -->
    			<?php endif; ?>
    		</div>
    	</div>
    
    <?php get_footer(); ?>
  2. scribu
    Member
    Posted 4 years ago #

    Just to be clear what i'm trying to do here is show a single post and then list all the posts below it (the same as is shown on the index page). Going to the second page should again load the same single post but list the second page of the total results.

    It would be easier to do it the other way around:

    Display that single post above the results page (modifying search.php or index.php).

  3. azenalex
    Member
    Posted 4 years ago #

    i'm not really sure how i would accomplish this? the index and search pages still need to not show a post initially but i'm open to setting some sort of argument that will define if a post is shown. I suppose i'm just not sure how to pass the same information that's being sent to the single.php page to index.php instead.

  4. scribu
    Member
    Posted 4 years ago #

    All you need to do is figure out when you want the post to be displayed and when not.

    The plugin works great on the index and archive pages but when I try to use it on the single page it ends up appending the paging arguments to the end of the single post url (eg. http://domain/2010/03/02/post-name/page/2/) which results in the same page getting loaded.

    Nope, that's done by WordPress. It has no way of knowing what set of posts you're expecting it to point to. That's why I said it's easier the other way around.

  5. azenalex
    Member
    Posted 4 years ago #

    ok, i guess i should have framed my question a little differently. how can i make clicking a link to a post on the index page do one of the following?

    a. load a post on the index page followed by the usual paginated lists of posts.
    b. (this sounds like the more elegant solution to me) have clicking a post link update a div via ajax to display a single post (to me this sounds something like having the ajax request update a div with the contents of single.php)

    if you can, please provide code snippets or a link to somewhere this may have already been done. thanks again!

  6. azenalex
    Member
    Posted 4 years ago #

    actually i'm not sure option 'b' will work since i still need the ability to link directly to a post (ie. i want ppl to be able to bookmark a single post).

  7. Svenl77
    Member
    Posted 4 years ago #

  8. azenalex
    Member
    Posted 4 years ago #

    oh wow... thanx so much!

  9. azenalex
    Member
    Posted 4 years ago #

    I also found this post which is pretty much what I've been trying to do.

    http://wordpress.org/support/topic/309327?replies=12

Topic Closed

This topic has been closed to new replies.

About this Topic