WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Next/Previous button on homepage ;( (10 posts)

  1. chuckyybed
    Member
    Posted 4 years ago #

    I'm using Streamline theme by StudioPress. There's not a Next/Previous button with official version on the homepage, but I need it just like this guy http://is.gd/6YKI0

    I inserted the code

    <div class="palignleft"><?php previous_posts_link('« Previous Page') ?></div>
    <div class="palignright"><?php next_posts_link('Next Page »') ?></div>

    I know it will not work because it's not inside the loop. But the loop is so complicated for me, I can't understand how to use it.

    Here's my home.php code, could someone show me how to use it?. Or just tell me the full code. I'll always be indebted to you for what you've done.

    <?php get_header(); ?>
    
    <div id="homepage">
    
    	<div id="contentleft">
    
    		<div class="postarea">
    
    		<?php if (function_exists('gallery_styles')) : ?>
    
            <div id="fcg">
                <?php include (ABSPATH . '/wp-content/plugins/featured-content-gallery/gallery.php'); ?>
            </div>
    
    		<?php endif; ?>
    
    			<div class="aheadline">
    				<h3><?php echo cat_id_to_name(get_theme_mod('featured_top_left')); ?></h3>
    			</div>
    
    			<div class="clear"></div>
    
    				<?php $recent = new WP_Query("cat=".get_theme_mod('featured_top_left')."&showposts=".get_theme_mod('featured_top_left_num')); while($recent->have_posts()) : $recent->the_post();?>
    				<?php if( get_post_meta($post->ID, "thumb", true) ): ?>
    				<a href="<?php the_permalink() ?>" rel="bookmark"><img class="thumb" src="<?php bloginfo('template_directory'); ?>/tools/timthumb.php?src=<?php echo get_post_meta($post->ID, "thumb", $single = true); ?>&h=<?php echo get_theme_mod('featured_top_left_thumb_height'); ?>&w=<?php echo get_theme_mod('featured_top_left_thumb_width'); ?>&zc=1" alt="<?php the_title(); ?>" /></a>
    				<?php else: ?>
    				<?php endif; ?>		                
    
    				<h1><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1>
    				<?php the_content_limit(300, "[".__("Read more", 'studiopress')."]"); ?>
    
    				<hr/>
    
    				<?php endwhile; ?>
                                    <div class="palignleft"><?php previous_posts_link('&laquo; Previous Page') ?></div>
    				<div class="palignright"><?php next_posts_link('Next Page &raquo;') ?></div>
    
    			</div>
    
    	</div>
    
    <?php include(TEMPLATEPATH."/sidebar.php");?>
    
    </div>
    
    <?php //The main column ends  ?>
    
    <?php get_footer(); ?>
  2. chuckyybed
    Member
    Posted 4 years ago #

    UP

  3. chuckyybed
    Member
    Posted 4 years ago #

    thank you

  4. chuckyybed
    Member
    Posted 4 years ago #

    T_T

  5. chuckyybed
    Member
    Posted 4 years ago #

    thank you

  6. vtxyzzy
    Member
    Posted 4 years ago #

    Unless I am mistaken, you don't want previous/next_post_link, you want 'paged':
    Try changing this:

    <?php $recent = new WP_Query("cat=".get_theme_mod('featured_top_left')."&showposts=".get_theme_mod('featured_top_left_num')); while($recent->have_posts()) : $recent->the_post();?>

    to this:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
       'cat' => get_theme_mod('featured_top_left'),
       'posts_per_page' => get_theme_mod('featured_top_left_num'),
       'paged' => $paged,
    }
    $recent = new WP_Query($args);
    while($recent->have_posts()) : $recent->the_post();?>
  7. chuckyybed
    Member
    Posted 4 years ago #

    Thank you so much. But it's not working.

    Parse error: syntax error, unexpected '}', expecting ')' in XXX/streamline/home.php on line 29

  8. vtxyzzy
    Member
    Posted 4 years ago #

    Sorry, my mistake. Please try this (or change the one line ahead of $recent =):

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
       'cat' => get_theme_mod('featured_top_left'),
       'posts_per_page' => get_theme_mod('featured_top_left_num'),
       'paged' => $paged,
    );
    $recent = new WP_Query($args);
    while($recent->have_posts()) : $recent->the_post();?>

    And, leave in the previous/next_posts_link lines.

  9. chuckyybed
    Member
    Posted 4 years ago #

    vtxyzzy You Awesome! You're absolutely gifted!
    Big Big XOXO for you! I'm extremely grateful to you.

  10. vtxyzzy
    Member
    Posted 4 years ago #

    You are welcome! Now, please use the dropdown at top right to mark this topic 'Resolved'.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags