Recent Topics

1 Jan 20, 2007 19:35    

Hi, I have recently upgraded to v1.9.1-beta and I am trying to get page numbers working on the blogs

Ideally I want to end up with the following format;

<< Prev Page | 1 2 3 4 5 6 | Next Page >>

I found the following code in http://forums.b2evolution.net/viewtopic.php?t=4804&highlight=next+numbers but it doesn't seem to work.

<?php



/*
 * posts_nav_link_number(-)
 *
 */
function posts_nav_link_number($before='', $after='', $pagelink='%', $pagedgroup='5', $page='')
{
  global $MainList, $paged, $result, $request, $posts_per_page, $what_to_show;
   
   $p = $MainList->$p;
   
  if( empty($p) && ($what_to_show == 'paged') && isset($MainList) )
   {
     
      $max_page = $MainList->get_max_paged();
     
      if( $max_page > 1 )
      {
         echo $before;
         
         $saved_paged = $paged;
         
         if(!$paged) $paged=1;
         $curr_paged = $paged;

         //find the $pagedgroup that we're in
         for($j=0; ($j*$pagedgroup) < $paged; $j++);
         $i=$j-1;
         //echo "\$i=$i; \$j=$j; \$k=$k; \$max_page=$max_page;";
         
         if($i > 0) {
         //   echo '<a href="';
         //   echo regenerate_url( 'paged', 'paged='.'1',$page);
         //   echo '">'.str_replace('%','1',$pagelink).'</a> ';
            echo '<a href="';
            echo regenerate_url( 'paged', 'paged='.($i*$pagedgroup),$page);
            echo '">&laquo;</a> ';
         }
         //echo "\$i=$i; \$j=$j; \$k=;$k; ";
         for( $k=($i * $pagedgroup) + 1; ($k <=  ($j * $pagedgroup) ) && $k <= $max_page; $k++) {
            if($k != $paged) {
               echo '<a href="';
               echo regenerate_url( 'paged', 'paged='.$k,$page);
               echo '">';
            }
            echo str_replace('%',$k,$pagelink);
            if($paged != $k) echo '</a> '; else echo ' ';
         //echo "\$i=$i; \$j=$j; \$k=$k; ";
         }
         
         //echo "\$i=$i; \$j=$j; \$k=$k; ";
         if ( $k <= $max_page)
         {
            //echo "\$i=$i; \$j=$j; \$k=$k; ";
            echo '<a href="';
            echo regenerate_url( 'paged', 'paged=' . $k ,$page);
            echo '">&raquo;</a> ';
         //   echo '<a href="';
         //   echo regenerate_url( 'paged', 'paged='. $max_page, $page);
         //   echo '">'.str_replace('%',$max_page,$pagelink).'</a>';
           
         }
      }
      $paged=$saved_paged;
      echo $after;
   }
}

?>

I have added the code to a file called hacks.php and placed the file in conf.

If it helps anyone I get the following error;

Notice: Undefined variable: p in /home/fhlinux188/w/walish.co.uk/user/htdocs/diary/conf/hacks.php on line 13

Notice: Undefined property: in /home/fhlinux188/w/walish.co.uk/user/htdocs/diary/conf/hacks.php on line 13

2 Jan 21, 2007 16:57

From a brief glance at that code it relies on register_globals being enabled as $p is not defined.

You could try to cure it with by changing this line, you never know, it may work ..... I'm an optimist :p

global $MainList, $paged, $result, $request, $posts_per_page, $what_to_show, $p;

¥

3 Jan 21, 2007 18:06

progress, but still not working correctly.

I am getting the following error now;

Notice: Undefined property: in /home/fhlinux188/w/walish.co.uk/user/htdocs/diary/conf/hacks.php on line 13

the error relating to $p has gone.

4 Jan 21, 2007 18:21

Damn, guess I'm gonna have to curb my optimism :(

¥

5 Mar 16, 2007 19:07

Does anyone have any idea on how to make this work. For me its the biggest problem with b2evo at present. I really am starting to need page numbers as a couple of my blogs are getting quite big. I would be really grateful to anyone who can help.

Thanks in advance.

6 Mar 17, 2007 01:50

Walish,

The problem I've had with hacking the core is this: When you next upgrade the software, you lose the hacks and (a) have to remember you did them (b) remember HOW you did them and (c) do them again (and hope they still work the same).

I've never liked the way page numbers are preformatted, out of b2evo and took a different approach. ( I just [url=http://randsco.com/index.php/all.php?p=200&page=2]hard-coded the links I WANTED[/url], with the formatting I WANTED, into each page. It's a tad of work initially, but once it's done ... it's completely future-proof and you don't have to go through the (a), (b) and (c) steps outlined above. )

I have no idea how you're blogging (b/c there's not a link to your blog), but I've got to believe that you don't make multi-paged posts on a daily basis (that's a LOT OF WRITING, if you do).

In any case, it *might* be another option you wish to consider.

Hope this helps.

7 Mar 17, 2007 09:21

http://www.walish.co.uk/page_projectrs_frameset.htm - This is good example of the problem I am having, as you can see its being used more as a diary than a blog and as a result the earliest entry is displayed first. This is why page numbers are starting to become essential.

I considered hard coding the links, but would this mean I would have to recode them every time the blog went onto another page?

9 Mar 18, 2007 16:52

I didn't realise I had removed those links, I must have done it by mistake when I was editing the skin. As you can probably tell, the site is along way from being finished, and the b2evo skin still needs work, I will re-add the links back in.

10 Mar 18, 2007 19:14

Just a quick note, I have added the 'powered by b2evolution' back in, sorry about that.

Also, while doing some browsing of these forums, I found exactly the thing I trying to get working.

http://fplanque.net/Blog/all - the page numbers right at the bottom is what I would like for my blogs. I think that site belongs to one of the creators of b2evo. Thanks for the help.

12 Mar 22, 2007 12:37

Francois is the main developer of b2evolution, so I doubt you'll find any 'hacks' on his blog(s). What you're looking at there is something you can probably expect to see in the 2.0 release.

13 Mar 22, 2007 16:39

conf/hacks.php

<?php
// fancy page numbers stuff
function am_post_links( $show = 6, $first = '|<', $prev_page = '<<', $prev_post = '<', $next_post = '>', $next_page = '>>', $last = '>|' )
{
	global $p, $paged, $MainList, $page;
	$show = intval( $show / 2 );
	$max_page = $MainList->get_max_paged();
	if( empty($p) )
	{
		if (!$paged) $paged = 1;
		$endpage = intval( $paged ) + $show - 1;
		$startpage = $endpage - ( $show * 2 ) + 1;
		if( $startpage < 1 )
		{
			$endpage = $show * 2;
			$startpage = 1;
		}
		if( $endpage > $max_page )
		{
			$endpage = $max_page;
			$startpage = $max_page - ( $show * 2 ) + 1;
		}
		if( $startpage < 1 )
			$startpage = 1;

		echo am_page_link( $first, 1 , $paged > 1).' &middot; ';
		echo am_page_link( $prev_page, ( $startpage > $show ? $startpage - $show : 1 ), $startpage > 1 ).' &middot; ';
		echo am_page_link( $prev_post, $paged - 1,  $paged > 1 ).' &middot; ';
		for( $i = $startpage; $i <= $endpage; $i++ )
			echo '[ '.am_page_link( $max_page - $i + 1, $i, $i != $paged ).' ] ';
		echo ' &middot; '.am_page_link( $next_post, $paged + 1,  $paged < $max_page );
		echo ' &middot; '.am_page_link( $next_page, ( ( $endpage + $show ) < $max_page ? $endpage + $show : $max_page ), $endpage < $max_page );
		echo ' &middot; '.am_page_link( $last, $max_page, $paged < $max_page );
	}
}

function am_page_link( $text, $page, $link )
{
	global $edited_Blog, $generating_static;
	return ( $link ? '<a href="'.( !isset($generating_static) ? regenerate_url( 'paged', 'paged='.$page ) : ( isset( $edited_Blog ) ? url_add_param( $edited_Blog->get('dynurl'), 'paged='.$page ) : '' ) ).'">' : '' ).$text.( $link ? '</a>' : '' );
}
?>

skins/<skin>/_main.php


<p id="navLinks">
<?php
if( $disp == 'posts' )
{
	am_post_links();
}
else
{
	next_post( '% &lt;--', '', 'yes');
	previous_post( '--&gt; %', '', 'yes' );
}
//	posts_nav_link();
?>
</p>

¥

14 Mar 22, 2007 23:27

yabba, you are a legend!! I do have one more small request, is it possible to make the highest page number be the most recent page number. I.E. 1 being the oldest, 10 being the newest.

The other small thing is making it highlight the page that is currently being displayed, but this isn't so important.

I promise to leave you all alone if I can get this working.

Thanks a lot for everyone's help.

15 Mar 23, 2007 10:14

Great... as usual, well done ¥åßßå
My only request to make this a little less confusing is the possibility for tooltips on the nav buttons and being able to style the #current page number.

16 Mar 23, 2007 14:21

<?php
// fancy page numbers stuff
function am_post_links( $params = array() )
{
	// lets set all the defaults
	if( empty( $params[ 'show' ] ) ) $params[ 'show' ] = 6;		// number of pages to show
	$params['order' ] = ( empty( $params[ 'order' ] ) || strtolower( $params['order'] ) != 'desc'  ? 'asc' : 'desc' );	// Should the count ASCend or DESCend ?
	if( !isset( $params[ 'before_all' ] ) ) $params[ 'before_all' ] = '<p class="navLinks">';	// output before all items
	if( !isset( $params[ 'after_all' ] ) ) $params[ 'after_all' ] = '</p>';	// output after all items
	/* the rest follow a standard pattern
	 * linked		: string to output if item is linked %url% is replaced by the link url
	 * unlinked	: string to output if item is not linked, leave blank to supress output
	 * %page% will be replaced by the page number
	*/
	if( !isset( $params[ 'first' ]['linked'] ) ) $params[ 'first' ]['linked'] = '[ <a href="%url%" title="First page">|&lt;</a> ]';
	if( !isset( $params[ 'first' ]['unlinked'] ) ) $params[ 'first' ]['unlinked'] = '[ |&lt; ]';
	if( !isset( $params[ 'prev_page' ]['linked'] ) ) $params[ 'prev_page' ]['linked'] = '[ <a href="%url%" title="Previous 6 pages">&lt;&lt;</a> ]';
	if( !isset( $params[ 'prev_page' ]['unlinked'] ) ) $params[ 'prev_page' ]['unlinked'] = '[ &lt;&lt; ]';
	if( !isset( $params[ 'prev_post' ]['linked'] ) ) $params[ 'prev_post' ]['linked'] = '[ <a href="%url%" title="Previous post">&lt;</a> ]';
	if( !isset( $params[ 'prev_post' ]['unlinked'] ) ) $params[ 'prev_post' ]['unlinked'] = '[ &lt; ]';
	if( !isset( $params[ 'last' ]['linked'] ) ) $params[ 'last' ]['linked'] = '[ <a href="%url%" title="Last page">&gt;|</a> ]';
	if( !isset( $params[ 'last' ]['unlinked'] ) ) $params[ 'last' ]['unlinked'] = '[ &gt;| ]';
	if( !isset( $params[ 'next_page' ]['linked'] ) ) $params[ 'next_page' ]['linked'] = '[ <a href="%url%" title="Next 6 pages">&gt;&gt;</a> ]';
	if( !isset( $params[ 'next_page' ]['unlinked'] ) ) $params[ 'next_page' ]['unlinked'] = '[ &gt;&gt; ]';
	if( !isset( $params[ 'next_post' ]['linked'] ) ) $params[ 'next_post' ]['linked'] = '[ <a href="%url%" title="Next post">&gt;</a> ]';
	if( !isset( $params[ 'next_post' ]['unlinked'] ) ) $params[ 'next_post' ]['unlinked'] = '[ &gt; ]';
	if( !isset( $params[ 'page' ]['linked'] ) ) $params[ 'page' ]['linked'] = '[ <a href="%url%" title="Page %page%">%page%</a> ]';
	if( !isset( $params[ 'page' ]['unlinked'] ) ) $params[ 'page' ]['unlinked'] = '[ %page% ]'; // this means it's the current page ;)

	/* theoretically you shouldn't need to change anything from here on */
	global $p, $paged, $MainList, $page;
	if( empty( $MainList ) ) return;
	$show = intval( $params[ 'show' ] / 2 );
	$max_page = $MainList->get_max_paged();
	if( $max_page == 1 ) return; // only one page 
	if( empty($p) )
	{
		if (!$paged) $paged = 1;
		$endpage = intval( $paged ) + $show - 1;
		$startpage = $endpage - ( $show * 2 ) + 1;
		if( $startpage < 1 )
		{
			$endpage = $show * 2;
			$startpage = 1;
		}
		if( $endpage > $max_page )
		{
			$endpage = $max_page;
			$startpage = $max_page - ( $show * 2 ) + 1;
		}
		if( $startpage < 1 )
			$startpage = 1;

		$output = am_page_link( ( $paged > 1 ? $params['first']['linked'] : $params['first']['unlinked'] ), 1);
		$output .= am_page_link( ( $startpage > 1 ? $params['prev_page']['linked'] : $params['prev_page']['unlinked'] ), ( $startpage > $show ? $startpage - $show : 1 ) ) ;
		$output .= am_page_link( ( $paged > 1 ? $params['prev_post']['linked'] : $params['prev_post']['unlinked'] ), $paged - 1 ) ;

		for( $i = $startpage; $i <= $endpage; $i++ )
			$output .= am_page_link( ( $i == $paged ? $params['page']['unlinked'] : $params['page']['linked'] ), ( $params['order'] == 'asc' ? $i : $max_page - $i ) ) ;

		$output .= am_page_link( ($paged < $max_page ? $params['next_post']['linked'] : $params['next_post']['unlinked'] ), $paged + 1 ) ;
		$output .= am_page_link( ($endpage < $max_page ? $params['next_page']['linked'] : $params['next_page']['unlinked'] ), ( ( $endpage + $show ) < $max_page ? $endpage + $show : $max_page ) ) ;
		$output .= am_page_link( ($paged < $max_page ? $params['last']['linked'] : $params['last']['unlinked'] ), $max_page);

	}
	$output = ( empty( $output ) ? '' : $params['before_all'].$output.$params['after_all'] );
	if( empty( $params['no_echo'] ) ) echo $output;
	return $output;
}

function am_page_link( $text, $page )
{
	global $edited_Blog, $generating_static;
	$url = ( !isset($generating_static) ? regenerate_url( 'paged', 'paged='.$page ) : ( isset( $edited_Blog ) ? url_add_param( $edited_Blog->get('dynurl'), 'paged='.$page ) : '' ) );
	return str_replace( array( '%url%', '%page%' ), array( $url, $page ), $text );
}
?>


There's a shedload of params, but they should all be self explanatory

¥

17 Mar 23, 2007 15:03

@ the Killer Expert
First thanks for the fully optioned model :)
Question
Does pagination like this add much to server load?

18 Mar 23, 2007 15:25

John,

Short answer: No.

The function uses existing parameters that are defined when the $mainList is built (i.e., the work has already been done and the parameters filled).

As an academic continuance ... I remember having a discussion with the British Blabba one time about whether or not using the anti-spam black-list was a "drag" on resources. (And learning that IF you turn on debug, in _advanced.php *i think* you can see the actual amount of time - %age - that each DB query that b2evo does, takes up ... and get a gauge for how "resource intensive" various components are).

What I learned? The black-list loads relatively quickly! (And that debug is useful for things other than debugging!) ;)

Hope this helps.

19 Mar 23, 2007 15:42

Also, if you wanted page links in multiple places then there's a param to not echo out the answer, so you could do :-

$fred = am_post_links( array('no_echo' => true ) );
echo $fred;

.....


echo $fred;


...


echo $fred;


;)

¥

20 Mar 23, 2007 15:48

Just to give you an example of how you *could* use the parameters :-

	am_post_links(	array(
			'first' => array(
				'linked' => '<li class="pg_first"><a href="%url%" title="First page">|&lt;</a></li>',
				'unlinked' => '<li class="pg_first">|&lt;</li>',
				),
			'prev_page' => array(
				'linked' => '<li class="pg_prevpg"><a href="%url%" title="Previous 6 pages">&lt;&lt;</a></li>',
				'unlinked' => '<li class="pg_prevpg">&lt;&lt;</li>',
				),
 			'prev_post' => array(
				'linked' => '<li class="pg_prevpst"><a href="%url%" title="Previous post">&lt;</a></li><li class="pg_left">&nbsp;</li>',
				'unlinked' => '<li class="pg_prevpst">&lt;</li><li class="pg_left">&nbsp;</li>',
				),

 			'next_post' => array(
				'linked' => '<li class="pg_right">&nbsp;</li><li class="pg_nextpst"><a href="%url%" title="Next post">&gt;</a></li>',
				'unlinked' => '<li class="pg_right">&nbsp;</li><li class="pg_nextpst">&lt;</li>',
				),
			'next_page' => array(
				'linked' => '<li class="pg_nextpg"><a href="%url%" title="Next 6 pages">&gt;&gt;</a></li>',
				'unlinked' => '<li class="pg_nextpg">&lt;&lt;</li>',
				),
			'last' => array(
				'linked' => '<li class="pg_last"><a href="%url%" title="Last page">&gt;|</a></li>',
				'unlinked' => '<li class="pg_last">&gt;|</li>',
				),
 			'page' => array(
				'linked' => '<li class="pg_link"><a href="%url%" title="Previous post">%page%</a></li>',
				'unlinked' => '<li class="pg_current">%page%</li>',
				),
			'before_all' => '<ul class="pg_box">',
			'after_all' => '</ul>'
			));

¥

21 Mar 23, 2007 15:52

Thanks for the confirmation Scott
@¥åßßå
I installed this as hacks.php but got errors all over the place.

Does the Nav bit for _main.php change for this update?
or have I just missed something?

22 Mar 23, 2007 15:56

wierd, what were your errors?

your _main.php code only needs changing if you want something different for the parameters ( I posted an example call above )

¥

23 Mar 23, 2007 16:02

EDIT :oops: My stupid mistaken code block removed

This appears where the nav links should be..

Fatal error: Call to undefined function: am_post_links() in /home/wow-factor/skins/custom_wow/_main.php on line 174

24 Mar 23, 2007 16:05

lol, muppet, add <?php ?> tags ;)

¥

*edit*
I added them to my post above so you should just be able to copy+paste ;)

25 Mar 23, 2007 16:16

Bugger!!!! crawls off to join all the other cut and pasters :)
Works a treat

27 Mar 23, 2007 16:23

John,

Just pretend that you did it on purpose to give us all a good laugh! :D ;)

( Don't feel too bad, Yabba's always eager to point out my "muppet" moves ;) )

Tho ... he makes a fair few himself. (I guess we've all been there, done that)

28 Mar 24, 2007 17:52

John wrote:

Bugger!!!! crawls off to join all the other cut and pasters :)
Works a treat

John, is there any chance of getting the code you used for your page numbers, the formatting you have is exactly what I am trying to get with mine.

Thanks.

29 Mar 24, 2007 20:55

I'll grab it and post it here Walish

30 Mar 24, 2007 21:21

John wrote:

I'll grab it and post it here Walish

good man, thanks alot.

31 Mar 24, 2007 21:33

Once again all thanks to ¥åßßå for this great hack and for your request in the first place Walish

1. hacks.php
All I did with this is delete everything from the "unlinked" $params apart from the "current" [ %page% ]
Also used a div id "paginator" in "before_all" and "after_all"

<?php
// fancy page numbers stuff
function am_post_links( $params = array() )
{
    // lets set all the defaults
    if( empty( $params[ 'show' ] ) ) $params[ 'show' ] = 6;        // number of pages to show
    $params['order' ] = ( empty( $params[ 'order' ] ) || strtolower( $params['order'] ) != 'desc'  ? 'asc' : 'desc' );    // Should the count ASCend or DESCend ?
    if( !isset( $params[ 'before_all' ] ) ) $params[ 'before_all' ] = '<div id="paginator">';    // output before all items
    if( !isset( $params[ 'after_all' ] ) ) $params[ 'after_all' ] = '</div>';    // output after all items
    /* the rest follow a standard pattern
     * linked        : string to output if item is linked %url% is replaced by the link url
     * unlinked    : string to output if item is not linked, leave blank to supress output
     * %page% will be replaced by the page number
    */
    if( !isset( $params[ 'first' ]['linked'] ) ) $params[ 'first' ]['linked'] = ' <a href="%url%" title="First page">|&lt;</a> ';
    if( !isset( $params[ 'first' ]['unlinked'] ) ) $params[ 'first' ]['unlinked'] = '  ';
    if( !isset( $params[ 'prev_page' ]['linked'] ) ) $params[ 'prev_page' ]['linked'] = ' <a href="%url%" title="Previous 6 pages">&lt;&lt;</a> ';
    if( !isset( $params[ 'prev_page' ]['unlinked'] ) ) $params[ 'prev_page' ]['unlinked'] = '  ';
    if( !isset( $params[ 'prev_post' ]['linked'] ) ) $params[ 'prev_post' ]['linked'] = ' <a href="%url%" title="Previous page">&lt;</a> ';
    if( !isset( $params[ 'prev_post' ]['unlinked'] ) ) $params[ 'prev_post' ]['unlinked'] = '  ';
    if( !isset( $params[ 'last' ]['linked'] ) ) $params[ 'last' ]['linked'] = ' <a href="%url%" title="Last page">&gt;|</a> ';
    if( !isset( $params[ 'last' ]['unlinked'] ) ) $params[ 'last' ]['unlinked'] = '  ';
    if( !isset( $params[ 'next_page' ]['linked'] ) ) $params[ 'next_page' ]['linked'] = ' <a href="%url%" title="Next 6 pages">&gt;&gt;</a> ';
    if( !isset( $params[ 'next_page' ]['unlinked'] ) ) $params[ 'next_page' ]['unlinked'] = '  ';
    if( !isset( $params[ 'next_post' ]['linked'] ) ) $params[ 'next_post' ]['linked'] = ' <a href="%url%" title="Next page">&gt;</a> ';
    if( !isset( $params[ 'next_post' ]['unlinked'] ) ) $params[ 'next_post' ]['unlinked'] = '  ';
    if( !isset( $params[ 'page' ]['linked'] ) ) $params[ 'page' ]['linked'] = ' <a href="%url%" title="Page %page%">%page%</a> ';
    if( !isset( $params[ 'page' ]['unlinked'] ) ) $params[ 'page' ]['unlinked'] = '[ %page% ]'; // this means it's the current page ;)

    /* theoretically you shouldn't need to change anything from here on */
    global $p, $paged, $MainList, $page;
    $show = intval( $params[ 'show' ] / 2 );
    $max_page = $MainList->get_max_paged();
    if( empty($p) )
    {
        if (!$paged) $paged = 1;
        $endpage = intval( $paged ) + $show - 1;
        $startpage = $endpage - ( $show * 2 ) + 1;
        if( $startpage < 1 )
        {
            $endpage = $show * 2;
            $startpage = 1;
        }
        if( $endpage > $max_page )
        {
            $endpage = $max_page;
            $startpage = $max_page - ( $show * 2 ) + 1;
        }
        if( $startpage < 1 )
            $startpage = 1;

        $output = am_page_link( ( $paged > 1 ? $params['first']['linked'] : $params['first']['unlinked'] ), 1);
        $output .= am_page_link( ( $startpage > 1 ? $params['prev_page']['linked'] : $params['prev_page']['unlinked'] ), ( $startpage > $show ? $startpage - $show : 1 ) ) ;
        $output .= am_page_link( ( $paged > 1 ? $params['prev_post']['linked'] : $params['prev_post']['unlinked'] ), $paged - 1 ) ;

        for( $i = $startpage; $i <= $endpage; $i++ )
            $output .= am_page_link( ( $i == $paged ? $params['page']['unlinked'] : $params['page']['linked'] ), ( $params['order'] == 'asc' ? $i : $max_page - $i ) ) ;

        $output .= am_page_link( ($paged < $max_page ? $params['next_post']['linked'] : $params['next_post']['unlinked'] ), $paged + 1 ) ;
        $output .= am_page_link( ($endpage < $max_page ? $params['next_page']['linked'] : $params['next_page']['unlinked'] ), ( ( $endpage + $show ) < $max_page ? $endpage + $show : $max_page ) ) ;
        $output .= am_page_link( ($paged < $max_page ? $params['last']['linked'] : $params['last']['unlinked'] ), $max_page);

    }
    $output = ( empty( $output ) ? '' : $params['before_all'].$output.$params['after_all'] );
    if( empty( $params['no_echo'] ) ) echo $output;
    return $output;
}

function am_page_link( $text, $page )
{
    global $edited_Blog, $generating_static;
    $url = ( !isset($generating_static) ? regenerate_url( 'paged', 'paged='.$page ) : ( isset( $edited_Blog ) ? url_add_param( $edited_Blog->get('dynurl'), 'paged='.$page ) : '' ) );
    return str_replace( array( '%url%', '%page%' ), array( $url, $page ), $text );
} ?>

2. #paginator CSS, added to my main CSS file ..

#paginator {text-align:center;color:#999;margin:0 auto;width:100%;} /* sets color for "current" [page] */
#paginator a{color:#D95;background:#ffe;padding:1px 2px;}/* links style*/
#paginator a:hover{color:#fff;background:#d95;}/*hover style*/

3. _main.php where I altered the next post/previous post to get it centered on one line. Still needs to be positioned better for single post view.

// ---------------------------------- END OF POSTS ------------------------------------ ?>
    	<?php
if( $disp == 'posts' )
{
    am_post_links();
}
else
{
    next_post( '<p class="center">&lt;- %&nbsp;&nbsp;', '', 'yes'  );
    previous_post( '&nbsp;&nbsp;% -&gt;</p>', '', 'yes' );
}
//    posts_nav_link();
?> 
	
 <?php // ---------------- START OF INCLUDES FOR LAST COMMENTS, STATS ETC. ----------------

32 Mar 25, 2007 03:45

That is some amazing work by ¥åßßå (he is the "Killer expert") and then by John to do the appropriate number order display (along with the css change to do the highlighting).

I noticed John that you have left off the

?>

at the end of your conf/hacks.php code. I figured that was just you being humorous.

This is all very remarkable. It works like a charm.

33 Mar 25, 2007 04:05

No, not trying to be funny, just a lousy cut n paster early on a Sunday morning :)

34 Mar 25, 2007 10:39

 am_post_links(    array(
            'first' => array(
                'linked' => ' <a href="%url%" title="First page">|&lt;</a>',
                'unlinked' => ' ',
                ),
            'prev_page' => array(
                'linked' => ' <a href="%url%" title="Previous 6 pages">&lt;&lt;</a>',
                'unlinked' => ' ',
                ),
             'prev_post' => array(
                'linked' => ' <a href="%url%" title="Previous post">&lt;</a>',
                'unlinked' => ' ',
                ),

             'next_post' => array(
                'linked' => ' <a href="%url%" title="Next post">&gt;</a>',
                'unlinked' => ' ',
                ),
            'next_page' => array(
                'linked' => ' <a href="%url%" title="Next 6 pages">&gt;&gt;</a>',
                'unlinked' => ' ',
                ),
            'last' => array(
                'linked' => ' <a href="%url%" title="Last page">&gt;|</a>',
                'unlinked' => ' ',
                ),
             'page' => array(
                'linked' => ' <a href="%url%" title="Previous post">%page%</a>',
                'unlinked' => '[ %page% ]',
                ),
            'before_all' => '<div id="paginator">',
            'after_all' => '</div>'
            )
     );

;)

¥

35 Mar 25, 2007 11:04

Sweet one Killer... :)
It doesn't play well with ?disp= pages.. well not mine anyhow !!!

Also, how would you recommend including the single post element as well?

next_post( '<p class="center">&lt;- %&nbsp;&nbsp;', '', 'yes'  );
    previous_post( '&nbsp;&nbsp;% -&gt;</p>', '', 'yes' ); 

36 Mar 25, 2007 12:24

Which disp= pages don't work for you?

Your single post stuff will only work properly if there's a prev && next post, you'd be better wrapping it differently

echo '<p class="center">';
next_post( '&lt;- %&nbsp;&nbsp;', '', 'yes'  );
previous_post( '&nbsp;&nbsp;% -&gt;', '', 'yes' );
echo '</p>';

¥

37 Mar 25, 2007 12:33

It gave an error on the "contact" page and that Submit form page you helped me with.

I'll look into it and see what I can find.

Cheers

38 Mar 25, 2007 12:48

The error for pages like disp=arcdir etc is...

Fatal error: Call to a member function on a non-object in /home/wow-factor/conf/hacks.php on line 33

that line is

$max_page = $MainList->get_max_paged();

from the following section of hacks.php

/* theoretically you shouldn't need to change anything from here on */
global $p, $paged, $MainList, $page;
$show = intval( $params[ 'show' ] / 2 );
$max_page = $MainList->get_max_paged();
if( empty($p) )

39 Mar 25, 2007 14:34

just after the "global" line add

if( empty( $MainList ) ) return;

and that should cure your error

¥

*edit*
I edited my original code to add it in 'cos I know yer just a copy+paste boy at heart :roll:

40 Mar 25, 2007 14:55

I edited my original code to add it in 'cos I know yer just a copy+paste boy at heart

Settle pettle.... all that happened yesterday, I'm reformed B)

41 Mar 25, 2007 15:07

Still tickles me ;)

Do you have a dev/test blog where you can break things? If so I'm in the middle of playing with our code plugin and if you want to have a go at breaking it I'll send you a copy ..... it really isn't ready for a live blog yet though ( it stores things in the db different, and I haven't coded in the old style yet, so any current code posts will break) ........ but it has some [url=http://dev.astonishme.co.uk/index.php]cool new features[/url] ;)

¥

42 Mar 25, 2007 15:45

No I don't have my b2 on a test server... yet, but your making it tempting.

The update you just posted works well, except when looking at a single post.
At the bottom it displays the next and previous posts just fine but also posts [ 1 ] immediately above it ???

43 Mar 25, 2007 15:52

I guess yer just gonna have to wait for the release version ;)

This *should* work, find this bit of the original code and add the new bit

   $max_page = $MainList->get_max_paged();
    if( $max_page == 1 ) return; // only one page

¥

44 Mar 25, 2007 16:04

:) I somehow think you will be glad I just have to wait

Your fix *did* work

45 Mar 25, 2007 16:10

Bob on, I've amended my original post ;)

¥

46 Mar 25, 2007 16:29

I have a slight problem, everything is working fine with firefox, but I have just had it pointed out to me that when viewed in Internet Explorer our skin isn't working, and the following error is appearing at the top of the page.

Warning: Cannot modify header information - headers already sent by (output started at /home/fhlinux188/w/walish.co.uk/user/htdocs/diary/conf/hacks.php:7) in /home/fhlinux188/w/walish.co.uk/user/htdocs/diary/inc/MODEL/skins/_skin.funcs.php on line 71

I am also getting this error in the admin section in any browser.

Warning: Cannot modify header information - headers already sent by (output started at /home/fhlinux188/w/walish.co.uk/user/htdocs/diary/conf/hacks.php:7) in /home/fhlinux188/w/walish.co.uk/user/htdocs/diary/inc/VIEW/_menutop.php on line 39

Help?!

47 Mar 25, 2007 16:30

I should add, the problem with IE not using the skin has only started since I put the page number code in, maybe I did something wrong, but I can't find it.

48 Mar 25, 2007 16:32

Its going from bad to worse now, I thought I should check all the other functions since I now knew there were a couple of minor issues. I get this little lot when logging out of b2evo

Warning: Cannot modify header information - headers already sent by (output started at /home/fhlinux188/w/walish.co.uk/user/htdocs/diary/conf/hacks.php:7) in /home/fhlinux188/w/walish.co.uk/user/htdocs/diary/inc/MODEL/sessions/_session.class.php on line 262

Warning: Cannot modify header information - headers already sent by (output started at /home/fhlinux188/w/walish.co.uk/user/htdocs/diary/conf/hacks.php:7) in /home/fhlinux188/w/walish.co.uk/user/htdocs/diary/inc/_misc/_misc.funcs.php on line 2851

Warning: Cannot modify header information - headers already sent by (output started at /home/fhlinux188/w/walish.co.uk/user/htdocs/diary/conf/hacks.php:7) in /home/fhlinux188/w/walish.co.uk/user/htdocs/diary/inc/_misc/_misc.funcs.php on line 2852

Warning: Cannot modify header information - headers already sent by (output started at /home/fhlinux188/w/walish.co.uk/user/htdocs/diary/conf/hacks.php:7) in /home/fhlinux188/w/walish.co.uk/user/htdocs/diary/inc/_misc/_misc.funcs.php on line 2853

Warning: Cannot modify header information - headers already sent by (output started at /home/fhlinux188/w/walish.co.uk/user/htdocs/diary/conf/hacks.php:7) in /home/fhlinux188/w/walish.co.uk/user/htdocs/diary/inc/_misc/_misc.funcs.php on line 2854

Warning: Cannot modify header information - headers already sent by (output started at /home/fhlinux188/w/walish.co.uk/user/htdocs/diary/conf/hacks.php:7) in /home/fhlinux188/w/walish.co.uk/user/htdocs/diary/inc/_misc/_misc.funcs.php on line 2931

Warning: Cannot modify header information - headers already sent by (output started at /home/fhlinux188/w/walish.co.uk/user/htdocs/diary/conf/hacks.php:7) in /home/fhlinux188/w/walish.co.uk/user/htdocs/diary/inc/_misc/_misc.funcs.php on line 2933

49 Mar 25, 2007 16:32

Can you post lines 1 -> 7 of your hacks.php?

¥

50 Mar 25, 2007 16:35

i was right, i did something stupid. I used dreamweaver to make the hacks.php file and I forgot to take the default bits of code out that it adds. The skin is now working in IE.

Im still getting the errors on logout and in the admin section though.

Also, discovered this one when logging in.

Warning: Cannot modify header information - headers already sent by (output started at /home/fhlinux188/w/walish.co.uk/user/htdocs/diary/conf/hacks.php:71) in /home/fhlinux188/w/walish.co.uk/user/htdocs/diary/inc/VIEW/login/_header.php on line 29

51 Mar 25, 2007 16:36

¥åßßå wrote:

Can you post lines 1 -> 7 of your hacks.php?

¥

¥

52 Mar 25, 2007 16:39

Sorry, my bad. I have posted the whole thing below just in case.

<?php
// fancy page numbers stuff
function am_post_links( $params = array() )
{
    // lets set all the defaults
    if( empty( $params[ 'show' ] ) ) $params[ 'show' ] = 6;        // number of pages to show
    $params['order' ] = ( empty( $params[ 'order' ] ) || strtolower( $params['order'] ) != 'desc'  ? 'asc' : 'desc' );    // Should the count ASCend or DESCend ?
    if( !isset( $params[ 'before_all' ] ) ) $params[ 'before_all' ] = '<div id="paginator">';    // output before all items
    if( !isset( $params[ 'after_all' ] ) ) $params[ 'after_all' ] = '</div>';    // output after all items
    /* the rest follow a standard pattern
     * linked        : string to output if item is linked %url% is replaced by the link url
     * unlinked    : string to output if item is not linked, leave blank to supress output
     * %page% will be replaced by the page number
    */
    if( !isset( $params[ 'first' ]['linked'] ) ) $params[ 'first' ]['linked'] = ' <a href="%url%" title="First page">|&lt;</a> ';
    if( !isset( $params[ 'first' ]['unlinked'] ) ) $params[ 'first' ]['unlinked'] = '  ';
    if( !isset( $params[ 'prev_page' ]['unlinked'] ) ) $params[ 'prev_page' ]['unlinked'] = '  ';
    if( !isset( $params[ 'prev_post' ]['linked'] ) ) $params[ 'prev_post' ]['linked'] = ' <a href="%url%" title="Previous page">&lt;</a> ';
    if( !isset( $params[ 'prev_post' ]['unlinked'] ) ) $params[ 'prev_post' ]['unlinked'] = '  ';
    if( !isset( $params[ 'last' ]['linked'] ) ) $params[ 'last' ]['linked'] = ' <a href="%url%" title="Last page">&gt;|</a> ';
    if( !isset( $params[ 'last' ]['unlinked'] ) ) $params[ 'last' ]['unlinked'] = '  ';
    if( !isset( $params[ 'next_page' ]['unlinked'] ) ) $params[ 'next_page' ]['unlinked'] = '  ';
    if( !isset( $params[ 'next_post' ]['linked'] ) ) $params[ 'next_post' ]['linked'] = ' <a href="%url%" title="Next page">&gt;</a> ';
    if( !isset( $params[ 'next_post' ]['unlinked'] ) ) $params[ 'next_post' ]['unlinked'] = '  ';
    if( !isset( $params[ 'page' ]['linked'] ) ) $params[ 'page' ]['linked'] = ' <a href="%url%" title="Page %page%">%page%</a> ';
    if( !isset( $params[ 'page' ]['unlinked'] ) ) $params[ 'page' ]['unlinked'] = '[ %page% ]'; // this means it's the current page ;)

    /* theoretically you shouldn't need to change anything from here on */
    global $p, $paged, $MainList, $page;
    $show = intval( $params[ 'show' ] / 2 );
    $max_page = $MainList->get_max_paged();
    if( empty($p) )
    {
        if (!$paged) $paged = 1;
        $endpage = intval( $paged ) + $show - 1;
        $startpage = $endpage - ( $show * 2 ) + 1;
        if( $startpage < 1 )
        {
            $endpage = $show * 2;
            $startpage = 1;
        }
        if( $endpage > $max_page )
        {
            $endpage = $max_page;
            $startpage = $max_page - ( $show * 2 ) + 1;
        }
        if( $startpage < 1 )
            $startpage = 1;

        $output = am_page_link( ( $paged > 1 ? $params['first']['linked'] : $params['first']['unlinked'] ), 1);
        $output .= am_page_link( ( $paged > 1 ? $params['prev_post']['linked'] : $params['prev_post']['unlinked'] ), $paged - 1 ) ;

        for( $i = $startpage; $i <= $endpage; $i++ )
            $output .= am_page_link( ( $i == $paged ? $params['page']['unlinked'] : $params['page']['linked'] ), ( $params['order'] == 'asc' ? $i : $max_page - $i ) ) ;

        $output .= am_page_link( ($paged < $max_page ? $params['next_post']['linked'] : $params['next_post']['unlinked'] ), $paged + 1 ) ;
        $output .= am_page_link( ($paged < $max_page ? $params['last']['linked'] : $params['last']['unlinked'] ), $max_page);

    }
    $output = ( empty( $output ) ? '' : $params['before_all'].$output.$params['after_all'] );
    if( empty( $params['no_echo'] ) ) echo $output;
    return $output;
}

function am_page_link( $text, $page )
{
    global $edited_Blog, $generating_static;
    $url = ( !isset($generating_static) ? regenerate_url( 'paged', 'paged='.$page ) : ( isset( $edited_Blog ) ? url_add_param( $edited_Blog->get('dynurl'), 'paged='.$page ) : '' ) );
    return str_replace( array( '%url%', '%page%' ), array( $url, $page ), $text );
} 
?> 

53 Mar 25, 2007 16:44

Ok, from what I can see there's nothing on lines 7 or 71 that would cause a header information error ( it's pretty much always caused by whitespace ).

Try copying the code again from my original post, pasting it into notepad and then reuploading it to your blog.

¥

54 Mar 25, 2007 16:52

Yabba, I found it, there was a white space on line 1 and line 74 (changed to these lines after I reuploaded it), I've removed them and all the errors have gone away. Thanks for your help.

I think we can call this solved now, as the page numbers are working as they should. As long as people copy and paste the code right unlike me and john. lol. Thanks again to everyone who help get the numbers working right.

Im very grateful.

55 Jun 12, 2007 23:37

This plugin doesn't work with 1.10.2 but works with 1.9.3 can you help me

56 Aug 16, 2007 19:31

Hi...

I´m using Walish's code from his "Sun Mar 25, 2007 15:39" posting with my b2evo 1.9.2 and in general it works really well. The other source codes posted prior to that I have tested too, but they resulted in error messages even when working...

Small question, when changing "asc" and "desc" at the top of the hacks.php it works not properly, because (I now have 50 pages) when going to page 49, it´s not the page before 50 but the second to last oldest page... you understand? Is there a way to fix this?

I would like to have [50] 49 48 47 < >| which actually works :lol:

57 Aug 28, 2010 13:32

i am kinda of a newbie... can you explain how to
include hacks.php into my index.php the right way?

i tried and keep getting a reguler back-forword nav links


Form is loading...