Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-03-07 22:20:33

tumain
Member
From: UK
Registered: 2011-07-29
Posts: 12
Website

How to get the order ID of an article made in a query?

Howdy.

I am creating a grid like portfolio page. Each grid is a portfolio piece / article and has 1 or 2 categories. At the top of the page are a list of category names. When you click one of these, the page rearranges just to show articles within that category.

I have a form called portfolio_listing which displays each portfolio piece within that grid.

<li data-id="" data-type="<txp:category1 /> <txp:category2 />"> <txp:permlink> <txp:upm_article_image type="thumbnail" limit="1" /><span class="title"><txp:title /><span class="role"><txp:if_keywords><txp:keywords /></txp:if_keywords></span></span> </txp:permlink> </li>

And this is called with the following, which is in a separate page:

<txp:article listform="portfolio_listing" form="portfolio" limit="999" />

To make it fully work, I just need to enter the ID of the cell (where it says data-id=”“ in the portfolio_listing code).

I did attempt to do this by using the txp:php tag to create a global variable in the separate page. I then tried to increment this variable within the portfolio_listing, then echo that value within the data-id=”…” part, but nothing appeared at all. Not sure if this is the correct way to do it?

I’m just trying to get the order ID of the article being iterated through (in the portfolio_listing form).

I hope this made sense lol.

Offline

#2 2012-03-07 22:35:43

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,001
Website GitHub

Re: How to get the order ID of an article made in a query?

There’s a version of rvm_counter here that works in memory rather than the db.

That said, I have also done it your way. Before your loop define the variable.

<txp:php>global $i;$i = 0;</txp:php>

Then within your loop do:

data-id="<txp:php>global $i; $i++; echo $i;</txp:php>"

The same principle can be used for other cases, e.g. the following outputs the class end-of-row to every 4th list item:

<li<txp:php>global $i; $i++; if($i % 4 == 0) { echo ' class="end-of-row"'; }</txp:php>>…</li>

TXP Builders – finely-crafted code, design and txp

Offline

#3 2012-03-07 23:31:46

tumain
Member
From: UK
Registered: 2011-07-29
Posts: 12
Website

Re: How to get the order ID of an article made in a query?

Thanks jakob – awesomely quick response. Worked straight away. =D

I have just realised what I did wrong from looking at your code. I just didn’t put the global in front of the $i in the portfolio_listing. Very silly of me.

Thanks again jakob!

Offline

Board footer

Powered by FluxBB