Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-05-11 18:13:07

hicks
Member
From: Portland, OR, USA (ex-UK)
Registered: 2009-05-08
Posts: 106
Website

separate article numbering for sections?

Hello again.

I have a feeling this will stump you.
On my home page, I’ll be hosting one section of blogs on the left — major articles — and snippet-style articles on the right. Now, I want my major articles to have article IDs as part of their presentation, but I want them to run sequentially without skipping numbers, which they won’t do as all articles — snippets and major — have IDs issued as they’re submitted. So with the plain old article_id tag, my numbers will skip.
Is there a way of numbering articles just in one section?

Thanks!

Offline

#2 2009-05-11 18:48:04

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,028
Website GitHub Mastodon Twitter

Re: separate article numbering for sections?

I guess you are not talking about the actual id as it appears in the database. Or are you?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2009-05-11 18:58:54

hicks
Member
From: Portland, OR, USA (ex-UK)
Registered: 2009-05-08
Posts: 106
Website

Re: separate article numbering for sections?

I imagine probably not, unless you can set different sections to, say, number separately in the database, perhaps with a letter prefix. Which I don’t think you can do (?). I just want my “major articles” section’s articles numbered 1 2 3 4 5 6… — without skipping numbers when “snippets” are entered as they would with article_id — on the page, automatically, somehow.

Offline

#4 2009-05-11 19:05:38

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: separate article numbering for sections?

You could store the number in a custom field for each article, or you could generate your own. Somewhere in your template, include the following:

<txp:php>
function majorArticleNum()
{
    static $ct = 1; // the initial # for major articles
    return $ct++;
}
</txp:php>

Then in your article form, modify the code from your previous question:

<txp:php>
printf("%03d", majorArticleNum());
</txp:php>

This will only work on one page, so the numbers will not be consistent on single-article pages. For instance, if you have five articles on your homepage, they’ll be numbered 1-5, but if you go to the permlink of an article, it’ll be #1 if there are no other articles present on that page. If you need the individual articles to have a consistent number that isn’t the article_id, then you’ll want to create a new DB table (e.g., major_num ( _article_id_, _num_)).

Offline

#5 2009-05-11 19:34:15

hicks
Member
From: Portland, OR, USA (ex-UK)
Registered: 2009-05-08
Posts: 106
Website

Re: separate article numbering for sections?

I thought it might involve making a new db table. Bearing in mind I’m a little new to Textpattern, would you be good enough to explain how to do that? As far as I know, which isn’t very far, each Textpattern installation needs it own database tables and you can’t have two feeds on one page… or can one installation use multiple sets of database tables?

Last edited by hicks (2009-05-11 19:34:42)

Offline

#6 2009-05-13 23:35:48

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: separate article numbering for sections?

If article numbers are that important, than this is what you could do. It’d be better as a plugin, but for something quick, try the following.

1. Create a table (execute the following SQL from the CLI or phpMyAdmin):

-- insert your table prefix if necessary (e.g., foomajor_num)
create table major_num(
    num        int(11) not null auto_increment,
    article_id int(11) not null,
    primary key(num)
);

2. On your main page or in a plugin (or somewhere that’s always included), do something like this:

<txp:php>
function majorArticleNum($id)
{
    $id = (int) $id;
    $rs = safe_field('num', 'major_num', "article_id = $id");
    if ($rs)
        return $rs;
    // create & get new #
    safe_insert('major_num', "article_id = $id");
    return mysql_insert_id();
}
</txp:php>

3. In your article form:

<txp:php>echo majorArticleNum(article_id());</txp:php>

Offline

#7 2009-05-22 20:41:38

hicks
Member
From: Portland, OR, USA (ex-UK)
Registered: 2009-05-08
Posts: 106
Website

Re: separate article numbering for sections?

Thanks for that, JM.

Offline

Board footer

Powered by FluxBB