Jump to content

could not able to retrive categories page from a referenced page


adrianmak
 Share

Recommended Posts

Here is the pages structure.

post-2272-0-98179000-1452235248_thumb.pn

the numeric in red is page id of a page.

Categories page is for categorization referenced by article page template, which is pages under "Recycling Library"

Let says, MRF Work Flows is categorized as Recycling Tour

I want to get the categories list from viewing an article and the categories list will be put on sidebar column.

When I retrieve the category page id from an article

$pagecat = $page->categories;

it returned 1030 (correct)

Then I want to get the category title from that id

$cat-title = $pages->get($pagecat)->title;

It returned the site root title, that is the name Home instead of category title

However, if i hard-coded the page id

$cat-title = $pages->get(1030)->title;

a category title returned

anything wrong with using the api ?

Link to comment
Share on other sites

Not sure exactly what the cause of this problem is here. But if you only need the title, you can do this:

$page->categories->title;

That is, you do not need to first get the category for the ID and request that page - as it is a page reference field you get the details anyway.

Link to comment
Share on other sites

Not sure exactly what the cause of this problem is here. But if you only need the title, you can do this:

$page->categories->title;

That is, you do not need to first get the category for the ID and request that page - as it is a page reference field you get the details anyway.

It's not working.

echo $page->categories;      // it will return the cat page id referenced.

However,

echo $page->categories->title   // empty, nothing shown on the web page.

Link to comment
Share on other sites

No, I mean the field on the MRF Work Flows page that specifies the category for that page. So what field type is the 'categories' field?

Sorry, I read that wrong. Was picturing a different screenie in my head.

Not sure why this isn't working. Could you try it on a fresh install of the latest stable and see what happens?

Is Debug Mode on?

Link to comment
Share on other sites

No, I mean the field on the MRF Work Flows page that specifies the category for that page. So what field type is the 'categories' field?

Sorry, I read that wrong. Was picturing a different screenie in my head.

Not sure why this isn't working. Could you try it on a fresh install of the latest stable and see what happens?

Is Debug Mode on?

yes, debug mode is on. And no errors generated on web page or log file.

Anyway, as u suggested, I will take a fresh installation with simple setup focus on this issue.

  • Like 1
Link to comment
Share on other sites

I just installed a fresh copy of pw 2.7.2 with basic profile.

1. created a categories template (without a template file associated)

2. created categories pages with the above template

3. add a page field type associated with categories pages

4. add categories field in basic-page template

5. edit existing content with category selected and saved.

6. modifed existing basic-page.php template with

echo $page->body . $page->categories->title;

Unfortunately, it result is the same as the old one.

$page->categories->title   /// nothing outputted

$page->categories   /// category page id outputted

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...