Recent Topics

1 Jan 13, 2005 06:48    

Two bits in your _main.php file. The first goes in the posts loop, and I put mine up at the top because it was already there for a different hack.

$Item->anchor(); // Anchor for permalinks to refer to
$post_id_is = $main_cat_is = $author_is = 0;
if( $disp == 'single' ) {
$post_id_is = $Item->get('ID');
$main_cat_is = $Item->get('main_cat_ID');
$author_is = $Item->Author->get('ID');
} ?>


The second goes where your post_nav_link() function is.

<p class="center"><strong>
<?php posts_nav_link( ' || ', 'newer', 'older' );
if( $disp == 'single' ) {
if( ! $preview ) { 
single_post_nav_links( $post_id_is, $main_cat_is, $author_is );
}
} ?>
</strong></p>

Now add this to your conf/hacks.php, and if you don't have that file create it, and if you create it b2evo will read it:

/**
 * create links for previous and next posts in single post display by blog or cat or author
 *
 * single_post_nav_links( postid, maincatid, authorid, showfrom, prevtext, sprtr, nexttext );
 *
 * first three parameters come from stuff you add to your _main.php file.
 * showfrom can be 'allblogs' or 'thisblog' or 'maincat' or 'author' - default is 'allblogs'
 * prevtext and nextext can be whatever you like - default is the post title
 * sprtr is for between the previous and next post links - default is ' || '
 *
 * Many thanks to Jimmy {http://jimmy.j2.idv.tw/} for the much better query method in this version
 */

function single_post_nav_links( $postid='', $maincatid='', $authorid='', $showfrom='#', $prevtext='#', $sprtr='#', $nexttext='#' ) { // open function
	global $DB, $Settings, $tableposts, $tablecategories, $tablepostcats, $blog;

	if( ($postid == '') || ($maincatid == '') || ($authorid == '') ) {
		return true;
	}
	if( ($postid == 0) || ($maincatid == 0) || ($authorid == 0) ) {
		return true;
	}

	$first_before = '<span style="font-size:smaller;">';
	$second_before = '&lt;&lt; ';
	$first_after = ' &gt;&gt;';
	$second_after = '</span>';

	if( $showfrom == '#' ) {
		$showfrom = 'allblogs';
		}
	if( $prevtext == '#' ) {
		$use_prev_title = true;
		}
	if( $sprtr == '#' ) {
		$sprtr = ' || ';
		}
	if( $nexttext == '#' ) {
		$use_next_title = true;
		}

	$time_now = time();
	$datetime = date("Y-m-d h:i:s", $time_now + ($Settings->get('time_difference') * 3600));

	switch( $showfrom ) {
		case 'allblogs':
		$sql_p = "SELECT ID, post_title FROM $tableposts WHERE post_status = 'published' AND post_issue_date <= '$datetime' AND ID > $postid ORDER BY ID ASC LIMIT 0, 1";
		$sql_n = "SELECT ID, post_title FROM $tableposts WHERE post_status = 'published' AND post_issue_date <= '$datetime' AND ID < $postid ORDER BY ID DESC LIMIT 0, 1";
		break;
		case 'thisblog':
		$sql_p = "SELECT ID, post_title, post_category, cat_blog_ID FROM $tableposts JOIN $tablecategories ON ( post_category = cat_ID) WHERE post_status = 'published' AND post_issue_date <= '$datetime' AND cat_blog_ID = $blog AND ID > $postid ORDER BY ID ASC LIMIT 0, 1";
		$sql_n = "SELECT ID, post_title, post_category, cat_blog_ID FROM $tableposts JOIN $tablecategories ON ( post_category = cat_ID) WHERE post_status = 'published' AND post_issue_date <= '$datetime' AND cat_blog_ID = $blog AND ID < $postid ORDER BY ID DESC LIMIT 0, 1";
		break;
		case 'maincat':
		$sql_p = "SELECT ID, post_title, post_wordcount FROM $tableposts JOIN $tablepostcats ON ( post_category = postcat_cat_ID ) WHERE post_status = 'published' AND post_issue_date <= '$datetime' AND ID = postcat_post_ID AND postcat_cat_ID = $maincatid AND ID > $postid ORDER BY ID ASC LIMIT 0, 1";
		$sql_n = "SELECT ID, post_title, post_wordcount FROM $tableposts JOIN $tablepostcats ON ( post_category = postcat_cat_ID ) WHERE post_status = 'published' AND post_issue_date <= '$datetime' AND ID = postcat_post_ID AND postcat_cat_ID = $maincatid AND ID < $postid ORDER BY ID DESC LIMIT 0, 1";
		break;
		case 'author':
		$sql_p = "SELECT ID, post_title, post_author FROM $tableposts WHERE post_status = 'published' AND post_issue_date <= '$datetime' AND post_author = $authorid AND ID > $postid ORDER BY ID ASC LIMIT 0, 1";
		$sql_n = "SELECT ID, post_title, post_author FROM $tableposts WHERE post_status = 'published' AND post_issue_date <= '$datetime' AND post_author = $authorid AND ID < $postid ORDER BY ID DESC LIMIT 0, 1";
		break;
		}

	$results_p = $DB->get_results($sql_p);
	$results_n = $DB->get_results($sql_n);

	if( $results_p ) { // that means there is a previous post to display
		$prev_post_id = $results_p->ID;
		$post_title = stripslashes($results_p->post_title);
		$NewItem = Item_get_by_ID( $prev_post_id );
		$permalink = $NewItem->gen_permalink( '', '', false, '&' );
		if( $use_prev_title ) {
			$title = htmlspecialchars(stripslashes($results_p->post_title));
			} else {
			$title = $prevtext;
			}
		$prev_link = '<a href="'.$permalink.'" title="link to '.$post_title.' post">'.$title.'</a>';
		} else {
		$prev_link = '';
		} // end if results_p

	if( $results_n ) { // that means there is a next post to display
		$next_post_id = $results_n->ID;
		$post_title = stripslashes($results_n->post_title);
		$NewItem = Item_get_by_ID( $next_post_id );
		$permalink = $NewItem->gen_permalink( '', '', false, '&' );
		if( $use_next_title ) {
			$title = htmlspecialchars(stripslashes($results_n->post_title));
			} else {
			$title = $nexttext;
			}
		$next_link = '<a href="'.$permalink.'" title="link to '.$post_title.' post">'.$title.'</a>';
		} else {
		$next_link = '';
		} // end if results_n

	echo $first_before;
	echo $second_before;
	echo $prev_link.$sprtr.$next_link;
	echo $first_after;
	echo $second_after;
	}


Of course there's a <?php above that and a ?> after that, but you knew that. b2evo users are too smart to miss something like *that*. For some details on tweakability of the whole magoo check out [url=http://wonderwinds.com/hackblog.php/2005/01/12/sniggling_the_cruftulator]my blog post[/url]

EDIT: changed the first bit to force the new variables to 0 as per an issue that cropped up later in this thread
EDIT2: Tweaked it so it won't show a link to a future post, and to keep it out of a failure loop if there are no results to work with.
EDIT3: Almost a complete rewrite. Jimmy's better query is in here, which meant a lot of the other code could go byebye. Same overall end result so you should be able to just drop this in and run it.

2 Jan 13, 2005 20:24

I edited the function above. Up at the top of it where it (now) has three IFs that it might return from used to only be one. The first IF checks that you included the parameters in the function. The second and third are due to a tortured skin I sometimes use. I got a 30-second timeout error when trying to view a single post in that skin, so postid must have been either nothing or 0 (or at least that's my assumption). Anyway now you know.

I also have a bitty bug I want to remove. If there is no previous post it is still putting in the << things. It's not a fatal flaw - just cosmetically unappealing.

3 Feb 03, 2005 11:09

Hi, I have followed the instructions as displayed in your blog and almost everything works fine. The problem is after I create the file conf/hacks.php and add the function definitions, the RSS cannot be generated nor the Atom Feeds.

The message I get is:

Warning: Cannot modify header information - headers already sent by (output started at (the path)/blog/conf/hacks.php:115) in
(the path)/blog/xmlsrv/atom.php on line 21

BTW, line 115 in hacks.php is the last line of the file and I don't see anywhere there any header output routine.

Everything was working fine before.

Any idea?

Thanks for any help.

4 Feb 03, 2005 17:00

Uh oh...

I tested that hack in all it's possible configurations, but I tested in v11. It's possible it won't run on v10, but after a quick glance I don't see why. I have a v10 installation so I'll give it a shot later.

It's funny that it talks about an error on the last line and header already started and references the atom.php file line 21. Makes no sense to me! Usually when I see an error at the end of a file it's because I missed a } at the end of an if or a ; at the end of a line or a ' after something that got echoed or something like that. Can you try it again with it exactly as-is, meaning no customizations and no parameters (other than the required ones) in the call to the function?

5 Feb 04, 2005 16:22

Hi,

Well I had only changed the delimiters in the function call. Though, after removing that and trying again, it still keeps coming with the same error. But the problem occurs only when I try to get an RSS or Atom feed. The rest of the site seemed to be working just fine.

6 Feb 04, 2005 16:55

hmm... I already subscribe to my own rss2 feed and just now subscribed to my atom feed without issue, but I modified part of the hack for another hack so maybe that's worth a shot.

The first bit

$Item->anchor(); // Anchor for permalinks to refer to
if( $disp == 'single' ) {
   $post_id_is = $Item->get('ID');
   $main_cat_is = $Item->get('main_cat_ID');
   $author_is = $Item->Author->get('ID');
   } ?>

Change it to force a value for the variables when not on a single post page

$Item->anchor(); // Anchor for permalinks to refer to
$post_id_is = $main_cat_is = $author_is = 0;
if( $disp == 'single' ) {
   $post_id_is = $Item->get('ID');
   $main_cat_is = $Item->get('main_cat_ID');
   $author_is = $Item->Author->get('ID');
   } ?>

To be honest I doubt it will help. I was able to read my own feed before making that change, but who knows what evil lurks in the hearts of servers and feed readers?

If you still have problems leave the hack in place so I can see it and maybe figure out what's up.

??? I did not test it with regular URLs ??? Possible issue with that ???

7 Feb 04, 2005 17:10

the same error.

It's now in place, so you can see it.

I have this in _main.php

$Item->anchor(); // Anchor for permalinks to refer to
      locale_temp_switch( $Item->locale ); // Temporarily switch to post locale
      $post_id_is = $main_cat_is = $author_is = 0;
      if( $disp == 'single' ) {
        $post_id_is = $Item->get('ID');
        $main_cat_is = $Item->get('main_cat_ID');
        $author_is = $Item->Author->get('ID');
    }

and this:

<div align="center" class="prevnext">
    <p><strong><?php posts_nav_link(); 
      if( $disp == 'single' ) {
        if( ! $preview ) {
           single_post_nav_links($post_id_is, $main_cat_is, $author_is) ;/*'#','#',
          '|&nbsp;<a href="/blog/">Principal</a>&nbsp;|', '#' ); */
        }
      } ?></strong></p>
  </div>

8 Feb 04, 2005 17:51

Wow. As you would expect, I saw the error in your atom feed. I then set my blog to not use clean urls and had no problem. I then put your code into my main blog's _main.php file and had no problem. I then put the parts you had commented out into the parameter string and had no problem.

Sorry, but I don't understand why it's causing this problem.

I wonder if anyone out there has been able to use this on version 0.9.0.10?

9 Mar 03, 2005 03:32

super awesome work EdB! i love it. except there's a small prob i'm having, you see i usually "Edit timestamp" and post stuff a day into the future.

the single_post_nav_links function shows the link to the "future" post (but of course the blog won't display the future post), how do i get the function to obey the time and display only links to posts that have "come to pass" ;)

_________________
[url=http://www.gousty.com]gousty[/url]

10 Mar 05, 2005 04:53

I'll fix this after this weekend. It's an oversight on my part because I'm not in the habit of dealing with people who already know the future 8|

11 Mar 10, 2005 14:52

Okay got it. As soon as I post this I'll edit the initial post in this thread, but it's already available on [url=http://wonderwinds.com/hackblog.php/2005/01/12/sniggling_the_cruftulator]my blog[/url]. I also fixed a funky thing that could get it stuck in a loop forever throwing up an error about something stupid. I *think* I fixed that part. I tested the future post thing and it's okay but I didn't test my forever loop bug, which might actually have been a bug in my weatherblog. Blech. Too many hacks to know which one is the sloppy one!

12 Mar 10, 2005 15:04

hihi... nice plug-in~

I think you might be interest in query code below:

this return single previous post:

SELECT ID, post_title FROM $tableposts JOIN $tablepostcats ON ( ID = postcat_post_ID ) WHERE post_status = 'published' AND postcat_cat_ID = $maincatid AND ID > $postid ORDER BY ID ASC LIMIT 0, 1

this return single next post:

SELECT ID, post_title FROM $tableposts JOIN $tablepostcats ON ( ID = postcat_post_ID) WHERE post_status = 'published' AND postcat_cat_ID = $maincatid AND ID < $postid ORDER BY ID DESC LIMIT 0, 1 

These two were modified by yours, maybe can enhance the performance.

13 Mar 10, 2005 15:29

Thanks. Much simpler method of getting the previous and next, and therefore probably quicker. Every microsecond counts eh? I'll play with it when I have some time.

14 Mar 11, 2005 01:29

looks like i stumbled on it:

Fatal error: Maximum execution time of 30 seconds exceeded in ****/public_html/conf/hacks.php on line 60

the post was sitting just fine in the future, but when i changed the timestamp to one minute into the past it pulled that nifty error. also changed the title and URL title

line 59      for($tpi=0; ; ) {
line 60         foreach ($results as $findtpi) {
line 61            $checkme = $findtpi->ID;

my hacks.php only has your hack, and my b2evo core is fresh of download.

my changes, i don't think they did anything of consequence here:

i added some cosmetic in the $prev_link and $next_link
erased what was between the ' ' in the $first_before and the other 3 like it.
and removed the ".$sprtr" in "echo $prev_link.$sprtr.$next_link; "

hope this helps.
good luck, bud. u totaly rock!
------------------
[url=http://www.gousty.com/]gousty.com[/url]

15 Mar 11, 2005 17:10

gousty wrote:

... i added some cosmetic in the $prev_link and $next_link
erased what was between the ' ' in the $first_before and the other 3 like it.
and removed the ".$sprtr" in "echo $prev_link.$sprtr.$next_link; " ...

I think all the changes could have been done through parameters in the function call. I set it up so you could use the same function in multiple skins, but no biggie. Anyway I think I got it working well now. I added Jimmy's query thing from a couple of posts up, which let me take out a bunch of the crap that (I think) was causing the troubles.

Have fun!!!

16 Mar 17, 2005 05:00

i can't get the hack+jimmy version to work, running mysql ver 4.0.23-standard, php 4.3.10

MySQL error!

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 6(Errno=1064)

Your query:
SELECT ID, post_author, post_issue_date, post_mod_date, post_status, post_locale, post_content, post_title, post_urltitle, post_url, post_category, post_autobr, post_flags, post_wordcount, post_comments, post_renderers, cat_blog_ID FROM evo_posts INNER JOIN evo_categories ON post_category = cat_ID WHERE ID = 


this only happens when i go single page mode, when the address/url bar show a pretty link like "***/2005/03/16/splish_splash"

i've set up the "basic" skin with this hack, i put the hack in the skin it self at the very begining and renamed the funtion so it wouldn't conflict with hacks.php. i didn't edit the funtion or the call at all.

click the big permalink link at the bottom and scroll down to the very bottom to see the error first hand.

[url=http://www.gousty.com/index.php?skin=basic]here it is, CLICK![/url]

yeah i could've done most of the config in the function call but u know, the file was already open ;)
----------------
-[url=http://www.gousty.com]gousty.com[/url]

17 May 16, 2005 08:45

Hmmm.. I tried to add this hack over the weekend and I'm also getting the same error...

(Running MySQL 4.0.22-standard, php. 4.3.10)

(have currently taken out the hack for aesthetic purposes)

:-/

18 May 18, 2005 12:05

It's me again. I decided to try again now that there have been changes.

Now There's no problem with RSS feeds, BUT I get the following:

¡Error de MySQL!

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 6(Errno=1064)

Your query:
SELECT ID, post_author, post_issue_date, post_mod_date, post_status, post_locale, post_content, post_title, post_urltitle, post_url, post_category, post_autobr, post_flags, post_wordcount, post_comments, post_renderers, cat_blog_ID FROM evo_posts INNER JOIN evo_categories ON post_category = cat_ID WHERE ID =

line 6 of what file? It doesn't say. The only thing in conf/hacks.php is the one I copied from the post above.

Any idea? I'm running 0.9.0.10

19 Aug 12, 2005 17:12

Guess I found the error, at least it works now in my blog.

Change

$results_p = $DB->get_results($sql_p);
$results_n = $DB->get_results($sql_n);

to

$results_p = $DB->get_row($sql_p);
$results_n = $DB->get_row($sql_n);

Another thing I managed to fix for my blog:
at 05:30 pm [17:30] I didn't get a link to a post made at 08:30 am [08:30].

after changing

$datetime = date("Y-m-d h:i:s", $time_now + ($Settings->get('time_difference') * 3600));

to

$datetime = date("Y-m-d H:i:s", $time_now + ($Settings->get('time_difference') * 3600));

it also worked

20 Aug 12, 2005 17:36

Interesting... It works for me the way I documented it, but this wouldn't be the first time a server configuration issue made a functional hack not work for someone else. I'm going to test your method on my blog and see if it still works for me. If so then I'll change the original post in this thread to make it more globally suitable.

21 Aug 12, 2005 18:24

i guess the second thing results from the different localisations, but i can't proof that for I'm not soo much in to mysql and b2evo and the stuff.

as I (of course ;) ) use the german localisation, my timestamp is formatted to H:i:s instead of h:i:s a as it should be on your blog. That leads me to the question, whether it is possible in your hack to get the timeformat out of the localisationsystem.

And to a second question: don't you have a problem with a link to the newest post sometimes, because as far as I can see that, your hack doesn't make any difference between am and pm?!

And excuse my english, i hope you understand what I want to say :roll:

22 Jul 17, 2006 08:38

mistake wrote:

Guess I found the error, at least it works now in my blog.

Change...

I had the same problem and your solution fixed me up perfectly. Thanks!

I know nothing about MySQL, so I never would have puzzled my way out of that!


Form is loading...