adrianmak Posted January 8, 2016 Share Posted January 8, 2016 Here is the pages structure. 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 More sharing options...
adrianmak Posted January 9, 2016 Author Share Posted January 9, 2016 anybody help? Link to comment Share on other sites More sharing options...
Craig Posted January 10, 2016 Share Posted January 10, 2016 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 More sharing options...
adrianmak Posted January 10, 2016 Author Share Posted January 10, 2016 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 More sharing options...
Mike Rockett Posted January 10, 2016 Share Posted January 10, 2016 What field type are you using to store the category on the page? Question may be irrelevant, though, as you say it is returning the correct ID anyway. Link to comment Share on other sites More sharing options...
adrianmak Posted January 10, 2016 Author Share Posted January 10, 2016 What field type are you using to store the category on the page? Question may be irrelevant, though, as you say it is returning the correct ID anyway. Page type Link to comment Share on other sites More sharing options...
Mike Rockett Posted January 10, 2016 Share Posted January 10, 2016 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 More sharing options...
adrianmak Posted January 10, 2016 Author Share Posted January 10, 2016 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. 1 Link to comment Share on other sites More sharing options...
adrianmak Posted January 10, 2016 Author Share Posted January 10, 2016 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 More sharing options...
adrianmak Posted January 10, 2016 Author Share Posted January 10, 2016 Eventually, I knew what causing this "issue". My field was not setup properly. I have to choose "single page......." option in the Dereference in API. 1 Link to comment Share on other sites More sharing options...
Mike Rockett Posted January 10, 2016 Share Posted January 10, 2016 Eventually, I knew what causing this "issue". My field was not setup properly. I have to choose "single page......." option in the Dereference in API. BaiduShurufa_2016-1-10_16-36-28.png Aha!I thought it would be something like that. Good catch! Link to comment Share on other sites More sharing options...
Craig Posted January 10, 2016 Share Posted January 10, 2016 I was going to ask that next! Glad you've got it Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now