I'm using ANT to generate titles for book pages. At the moment I'm using the [nid] as part of the title. This is so book pages will automatically put themselves in order (I always want the book pages to be arranged in order of creation). It works as far as it goes but could be neater.

What I'd really like is for each book page to be automatically numbered, starting from 1 - so the first node added to a book gets titled, for example, "Parentbook 1", then the next to be added becomes "Parentbook 2" and so on.

My PHP-fu is basically nil; is this possible? Does the book module have the functionality to pull a "this node is the nth child of this book" value, or isn't that how it works?

Comments

BasM’s picture

I am working on something similar, generating auto-numbered companies codes for my system.
(I want them to be called B1, B2, B3, etc)

I created a table called 'companynr' in my database with a field called 'number' filled with 1 value: '0'.
I have set ANT to 'Automatically generate the title if the title field is left empty'

And my php script is:

<?php 
$result = db_query('SELECT number FROM {companynr}');
$value = db_result($result) +1;
db_query("UPDATE {companynr} SET number = $value");
return "B$value";
?>

All is working pretty well, except for the fact that the database value seems to be increasing by 2 and not 1.
The result is only even numbers: B2, B4, B6, etc.

If I remove the +1 from the database value it is not being updated at all, so my guess is the script is being runned twice, or I am overlooking something.

gaurav.kapoor’s picture

Issue summary: View changes
Status: Active » Fixed
gaurav.kapoor’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.