Recent Topics

1 Aug 18, 2007 00:29    

My b2evolution Version: 1.10.x

I'm trying to customize the appearance of the Previous Post / Next Post links inside the post loop... what I did was change/add approx lines 261 and 336 in _item.funcs.php from:


if( $previous == '#' ) $previous = T_('Previous post') . ': '; // line 261
and
if( $next == '#' ) $next = T_('Next post') . ': '; // line 336


to


if( $previous == '#' ) $previous = T_('Previous post') . ': ';
if( $previous == '1' ) $previous = T_('') . '';
and
if( $next == '#' ) $next = T_('Next post') . ': ';
if( $next == '1' ) $next = T_('') . '';


I'm calling this new code as so, in the post loop:


<?php
echo '<dl class="last"><dt>Previous Post:</dt><br /><dd>';
previous_post('%','1');    // link to previous post in single page mode
echo '</dd></dl><dl class="last"><dt>Next Post:</dt><br /><dd>';
next_post('%','1');             // link to next post in single page mode
echo '</dd></dl>';
?>

What this does is display Previous/Next text separately from the link itself and removes the << and >> around the links... However, the "Next Post:" text is still visible even on the very latest post on the blog even though there is no link to be displayed along with it, and the same situation exists for the Previous text on the very first post...

So, basically, what I'm looking for is a way to check for the condition of the post being the first post or the last post and to not display the entire corresponding link and header for the link in those situations... but to display both links for all posts inbetween. I'm not sure how, or if, that can be done inside the previous_post() next_post() code itself, which is why I've tried to separate it all... Any ideas...?

Essentially, I want to be able to separate the Previous / Next text from the link itself, and only have the Previous / Next text be displayed when there is an actual previous or next link to display...

jj.

2 Aug 18, 2007 00:43

So if i'm understanding correctly, this should work...

$n = sizeof($MainList->postIDarray);
// later on within your while loop
$last_Post_ID = $MainList->postIDarray[$n-1];
if ( $Item->ID === $last_Post_ID )
    // you are the last post in the list

3 Aug 19, 2007 21:48

That's a little beyond me... not sure how to begin building that in. I've made a few different attempts at getting the right link to display in the right situation but haven't gotten it running yet...

jj.

4 Aug 19, 2007 22:17

Ok, so somewhere in your skin's _main.php file you will have

	if( isset($MainList) ) $MainList->display_if_empty( '' ); // Display message if no post
	if( isset($MainList) ) while( $Item = & $MainList->get_item() )
	{

just change to

	if( isset($MainList) ) $n = sizeof($MainList->postIDarray); 
	if( isset($MainList) ) $MainList->display_if_empty( '' ); // Display message if no post
	if( isset($MainList) ) while( $Item = & $MainList->get_item() )
	{

Then with your code

<?php
echo '<dl class="last"><dt>Previous Post:</dt><br /><dd>';
previous_post('%','1');    // link to previous post in single page mode
echo '</dd></dl><dl class="last"><dt>Next Post:</dt><br /><dd>';
next_post('%','1');             // link to next post in single page mode
echo '</dd></dl>';
?>

change to

<?php
$last_Post_ID = $MainList->postIDarray[$n-1];
if ( $Item->ID === $last_Post_ID )
{
echo '<dl class="last"><dt>Previous Post:</dt><br /><dd>';
previous_post('%','1');    // link to previous post in single page mode
echo '</dd></dl><dl class="last"><dt>Next Post:</dt><br /><dd>';
next_post('%','1');             // link to next post in single page mode
echo '</dd></dl>';
}
?>

5 Aug 19, 2007 23:16

That's giving me a similar result to some of the other methods I tried... Basically what's happening now is that on the most recent post the "Next Post:" text still appears even though there is no link to go along with it...

What I'm trying to achieve is this:

If the post is the very first post on that blog, I would like to see only:
Next Post:
the title of the next post linked to that post

If the post is the very latest post on that blog, I would like to see only:
Previous Post:
the title of the previous post linked to that post

For every post between the first and latest on that blog, I would like to see both:
Next Post:
the title of the next post linked to that post
Previous Post:
the title of the previous post linked to that post

Getting the link to not appear hasn't been a problem.. I've achieved it several different ways now... The problem is getting the heading of "Previous Post:" or "Next Post:" to also not appear when there's no link for it, but at the same time to make the "Previous Post:" and "Next Post:" titles not be part of the links themselves.

You can see what I mean about how it currently looks here: http://blog.thedarksighed.com/main/2007/08/17/sites_banning_firefox_out_of_spite
That is the most recent post on that blog... The titles/links in question are on the left side of the post.

jj.

6 Aug 19, 2007 23:53

Ok


    if( isset($MainList) ) { $last_post_i = sizeof($MainList->postIDarray)-1; $i = -1; $MainList->display_if_empty( '' ); }
    if( isset($MainList) ) while( $Item = & $MainList->get_item() )
    {
        ++$i;

        // blah blah blah

       if ( $i !== 0 ) { // not first post
       echo '<dl class="last"><dt>Previous Post:</dt><br /><dd>';
       previous_post('%','1');    // link to previous post in single page mode
       echo '</dd></dl>';
       } if ( $i !== $last_post_i ) { // not last post
       echo '<dl class="last"><dt>Next Post:</dt><br /><dd>';
       next_post('%','1');             // link to next post in single page mode
       echo '</dd></dl>'; 
       }

       // blah blah blah
}

You may need to rename $i to something better...

7 Aug 20, 2007 00:08

And what was the point of your hack? in your first post?

8 Aug 20, 2007 00:14

I'll give that code a try after I have something to eat.

The point of the hack in the first post... the $previous == '1' part? That was so this particular skin can render in a slightly different way than the other skins on my system...

The default code:

if( $previous == '#' ) $previous = T_('Previous post') . ': ';


places the 'Previous post' text inside the 'a href'. Here I'm trying to separate it from the 'a href' and also to have it only render when applicable...

jj.

9 Aug 20, 2007 00:17

You could cheat if you want to get rid of that a href part by doing

echo '<!-- ';  previous_post('%', ' -->'.T_('Previous post') . ': <--'); echo '-->';


Form is loading...