WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Linking to Previous / Next Post? (22 posts)

  1. kurtiskronk
    Member
    Posted 5 years ago #

    I like this theme, but I don't like that there is no previous/next post linkage on the single pages. Is this easy to add with a quick tweak?

    http://kurtiskronk.com/2008/12/11/city-lights/

    You can see my page there for reference if needed. I'd like to have previous/next links with post titles at the top and bottom.

  2. MichaelH
    Member
    Posted 5 years ago #

    You can always look at the WordPress Default theme's wp-content/themes/default/single.php to see how it uses the previous_post_link and next_post_link.

  3. kurtiskronk
    Member
    Posted 5 years ago #

    Ah... so you can just pull that code from another theme? I've messed with it in other themes but it's total absence in this theme had me wondering if it could be added. Many thanks. :)

  4. kurtiskronk
    Member
    Posted 5 years ago #

    Hm... so where are all these functions located, like cfct_single()? Can't find them in the theme editor.

  5. MichaelH
    Member
    Posted 5 years ago #

    cfct_single is not a native WordPress function so must be a function specfic to your theme (or a plugin), so use WinGrep to search your wp-contents folder for that string.

  6. kurtiskronk
    Member
    Posted 5 years ago #

    I use a Mac. I'll do a search in BBEdit, though.

  7. kurtiskronk
    Member
    Posted 5 years ago #

    Okay, maybe I'm dense... but I am getting a bit of a run-around from all these files. Any chance someone could do this for me, or share the code you've used yourself to do this? I would think this is a pretty important thing, linking to previous / next posts, so that people can go through your content easily.

  8. kurtiskronk
    Member
    Posted 5 years ago #

    *ding dong*

  9. kurtiskronk
    Member
    Posted 5 years ago #

    I switched back to iNove while I wait for an answer on this - I like Carrington more but the previous/next thing is important to me and I can't figure it out.

  10. kurtiskronk
    Member
    Posted 5 years ago #

    Anyone...? *crickets chirping*

  11. figaro
    Member
    Posted 5 years ago #

    Is this what you are looking for?

    http://heraldleader.org/wordpress/

  12. Dgold
    Member
    Posted 5 years ago #

    Here's some code for ya, put it in Single.php (your theme's single post template)

    <div class="navigation">
    
    <?php previous_post_link('%link', '<img src="http://YOURSITE.COM/YOUR-PREVIOUS-POST-REWIND-ARROW-BUTTON.jpg"/> <strong>View the previous post!</strong>'); ?> 
    
    ------ Divide them how you want or make a new DIV ------ 
    
    <?php next_post_link('%link', '<strong>View the next post!</strong> <img src="http://YOURSITE.COM/YOUR-NEXT-POST-FORWARD-ARROW-BUTTON.jpg"/>'); ?></div>

    Or try this and mess around with it,

    <?php previous_post_link('&laquo %link', '%title'); ?>
    
    <?php next_post_link('%link &raquo', '%title'); ?>

    Enjoy!

  13. jabecker
    Member
    Posted 5 years ago #

    Try adding this code just below the start of the loop.

    <div>
    <?php if ($single) { ?>
    <?php } ?>
    <?php previous_post_link('%link'); ?><a href="<?php echo bloginfo('url'); ?>/index.php"> | Main | </a><?php next_post_link('%link'); ?>
    </div>

  14. kurtiskronk
    Member
    Posted 5 years ago #

    figaro: yes, that's precisely what i'm looking for with the previous/next links at the top. how'd you do it? and any clue how i could link to related posts above the comments?

    jabecker: what file are you referring to for putting that code in? (I tried putting it in loop-default.php, after the while loop started, after the end of the loop, and in a couple other spots, and none of those worked.

  15. Dgold
    Member
    Posted 5 years ago #

    The code that jabecker listed is the same basic code, similar method, as the code I listed. Mine included a way for you to put NEXT and PREVIOUS images (jpeg arrows back and forth) if you wish.

    jabecker's added the conditional statement for "if single page", which means you could plop it into your Main Index Template (probably index.php) if you do not have a Single.php.

    Mine was meant to put in Single.php --- so you would not need a conditional statement like that.

    Give it a try. You have these templates in your theme?

  16. figaro
    Member
    Posted 5 years ago #

    Go here http://heraldleader.org/wordpress/ and downlod the file in the latest post. I put directions in the post for you.

  17. jabecker
    Member
    Posted 5 years ago #

    kurtiskronk, what Dgold said is correct. In my theme, I don't have a single.php because my single pages are styled the same way as my main page. Also, I don't use pictures for my previous/next links.

    The code is in my index.php right after the start of the loop, which is the code that looks something like this:
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?

    Of course, if I'd pasted the code in correctly, that would have helped, too. It really should be:
    <div>
    <?php if ($single) { ?>
    <?php previous_post_link('%link'); ?><a href="<?php echo bloginfo('url'); ?>/index.php"> | Main | </a><?php next_post_link('%link'); ?>
    <?php } ?>
    </div>

    This is the part that does the work:
    <?php previous_post_link('%link'); ?><a href="<?php echo bloginfo('url'); ?>/index.php"> | Main | </a><?php next_post_link('%link'); ?>

    Since the code is in my index.php page, I need the conditional statement so it only shows up when it's a single post page. If you have a single.php and put it there, you would not need it. The <div> is wrapped around the code so that it can be styled. I have it centered.

  18. kurtiskronk
    Member
    Posted 5 years ago #

    figaro: The file you put up does exactly what I'm looking for with the previous/next links, but for some reason it messes with the placement of the title of the single post you're in?

    I altered the code a bit to this:

    <div id="content">
    <div class="navigation">
    <table width="100%" cellspacing="10" style="border-width: 0px;">
    <tr><td width="50%">
    <div style="float: left;"><?php previous_post_link('« %link') ?></div>
    </td><td width="50%">
    <div style="float: right;"><?php next_post_link('%link »') ?></div>
    </td></tr>
    </table>
    </div>

    only problem now is that it's giving me a table border even though I tell it not to.

  19. kurtiskronk
    Member
    Posted 5 years ago #

    This is what it looks like now, if you want to see it, with the table border and all:

    http://kurtiskronk.com/2008/12/12/two-cubed/

  20. figaro
    Member
    Posted 5 years ago #

    Humm...not sure where the table is coming from. I didn't put it in the file and it's not showing on my site. The only thing I added to the file is the following:

    <div id="content">
    <div class="navigation">
    <div class="alignleft">
    <?php previous_post_link('« %link') ?>
    </div>
    <div class="alignright"><?php next_post_link('%link »') ?>
    </div>
    </div>

    Look in the file and make sure there is no table html in that code. If not, then it must be coming from the styling in your theme...I'm using the same theme at the link below and have no table borders...

    http://heraldleader.org/wordpress/?p=13

  21. kurtiskronk
    Member
    Posted 5 years ago #

    No no, I added the table, so that the next/previous would each be on one half of the same line, I don't like it when they wrap one line on top of the other.

    And there is a problem that came from me putting your code before I modified it for some reason. Somehow, it messes up the placement of the post title, at least it does in Firefox, not sure about other browsers. For me, it would randomly indent it varying numbers of pixels

  22. kurtiskronk
    Member
    Posted 5 years ago #

    I went ahead and removed the table since I couldn't get some parts of the border to go away and I got it looking good enough anyways with a couple quick alterations to the code, as seen below:

    <div class="navigation" style="padding-top: 15px; padding-bottom: 10px;">
    	<div style="float: left;"><?php previous_post_link('&laquo; %link') ?></div>
    	<div style="float: right;"><?php next_post_link('%link &raquo;') ?></div>
    </div>

    I ended up putting this at the top of the post and at the bottom as well, above the comments.

    Here's the end result: http://kurtiskronk.com/2008/12/16/standing-in-wait/

    And for reference, for anyone else looking to do the same thing, here are the entire contents of my single_default.php for the Carrington theme:

    <?php
    
    // This file is part of the Carrington Theme for WordPress
    // http://carringtontheme.com
    //
    // Copyright (c) 2008 Crowd Favorite, Ltd. All rights reserved.
    // http://crowdfavorite.com
    //
    // Released under the GPL license
    // http://www.opensource.org/licenses/gpl-license.php
    //
    // **********************************************************************
    // This program is distributed in the hope that it will be useful, but
    // WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    // **********************************************************************
    
    if (__FILE__ == $_SERVER['SCRIPT_FILENAME']) { die(); }
    if (CFCT_DEBUG) { cfct_banner(__FILE__); }
    
    get_header();
    
    ?>
    
    <div id="content">
    
    <div class="navigation" style="padding-top: 15px; padding-bottom: 10px;">
    	<div style="float: left;"><?php previous_post_link('&laquo; %link') ?></div>
    	<div style="float: right;"><?php next_post_link('%link &raquo;') ?></div>
    </div>
    
    <?php
    	cfct_content();
    ?>
    
    <div class="navigation" style="padding-top: 15px; padding-bottom: 10px;">
    	<div style="float: left;"><?php previous_post_link('&laquo; %link') ?></div>
    	<div style="float: right;"><?php next_post_link('%link &raquo;') ?></div>
    </div>
    
    	<div id="comments">
    <?php
    	comments_template()
    ?>
    	</div><!--#comments-->
    </div><!--#content-->
    
    <?php
    get_sidebar();
    
    get_footer();
    
    ?>

    Many thanks to figaro, jabecker, and dgold for help doing this. Ended up being more simple than I realized, but the fact that this theme's code was so different from my other themes confused me thoroughly. :-D

Topic Closed

This topic has been closed to new replies.

About this Topic