Jump to content


Photo
- - - - -

A template for Custom Post Type


  • Please log in to reply
13 replies to this topic

#1 raquel_p

raquel_p

    Advanced Member

  • Members
  • 57 posts
  • Framework Version:2.3
  • Country: Country Flag

Posted 08 August 2011 - 11:57 AM

Still do not understand how to make templates for Post Custom Types in PlatformBase. I read

Please Login or Register to see this Hidden Content

and

Please Login or Register to see this Hidden Content

, but it is not clear to me how create these templates. Should I use hooks, template.override, boxes or sections? I want to customize a post type (not a page), especially entering the information of Custom Fields. Like I would in loop.single.php, if was TwentyTen. Developers: A tutorial in Docs will solve the doubt of many people.

#2 raquel_p

raquel_p

    Advanced Member

  • Members
  • 57 posts
  • Framework Version:2.3
  • Country: Country Flag

Posted 08 August 2011 - 12:20 PM

I move/override/save in PlatformBase a template.postloop.php (from PlatformPro), with my custom post type name: template.custom.php. Is this correct? But, I don??t know how I register/call this template.

#3 Kate

Kate

    Advocate

  • Members
  • 3039 posts

Posted 08 August 2011 - 12:49 PM

Hi Raquel, Did you try Adam's solution yet? Of modifying template.postloop.php? If you do, please make sure to copy it to the base file first.

#4 raquel_p

raquel_p

    Advanced Member

  • Members
  • 57 posts
  • Framework Version:2.3
  • Country: Country Flag

Posted 08 August 2011 - 02:11 PM

Hello Kate, Thanks for the tip. But who is Adam (this is his nickname)? Could you give me the link to his solution.

#5 drwatson

drwatson

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts

Posted 08 August 2011 - 02:54 PM

Hi Kate, i have the same question and im very interesting about the solution from adam. I dont found the solution from him on his site. a link would help us...thanks!

#6 kastelic

kastelic

    Advocate

  • Members

  • 3081 posts
  • Country: Country Flag

Posted 08 August 2011 - 10:45 PM

The solution is very simple. Go to Custom Post Types UI settings and edit your post type. Click on advanced options, and then check "has archive". Thats it, it will create an archive page for you that uses the pagelines loop, so it looks just like any other blog page.

#7 raquel_p

raquel_p

    Advanced Member

  • Members
  • 57 posts
  • Framework Version:2.3
  • Country: Country Flag

Posted 08 August 2011 - 11:13 PM

Ok, I understand. Logical. But where it will save the template? Where do I find and what's its name? I tried and not found.

#8 kastelic

kastelic

    Advocate

  • Members

  • 3081 posts
  • Country: Country Flag

Posted 08 August 2011 - 11:33 PM

It uses template.postloop.php, just like every post, page and archive. Say the name of your post type is "hotels". Once you enable it, it will be active at www.yoursite.com/hotels.

#9 raquel_p

raquel_p

    Advanced Member

  • Members
  • 57 posts
  • Framework Version:2.3
  • Country: Country Flag

Posted 09 August 2011 - 11:16 AM

Hi Kastelic, First of all. Thank you for trying to help me. Unfortunately, I'm starting to feel stupid. My custom post types are active. I can access them with permalinks, categorize them, list them, put them in the home and feed. The problem is how to customize the loop them. I activated the option "has archive" and nothing has apparently changed. I can not access the specific template of my post types. See if I understand: I need to customize them in the template.postloop.php, creating a new copy of this file, and placing him in platformbase. No need to create a file separately for each post types. The question is which function to start the loop itself each post type. If it is not asking too much, you could give me a small example?

#10 raquel_p

raquel_p

    Advanced Member

  • Members
  • 57 posts
  • Framework Version:2.3
  • Country: Country Flag

Posted 09 August 2011 - 01:02 PM

Kastelic: See if you quite understand my question: I want to a post type template, like a single post, not an archive for post types, like a post archive. I need a postloop for my post types.

#11 kastelic

kastelic

    Advocate

  • Members

  • 3081 posts
  • Country: Country Flag

Posted 09 August 2011 - 03:55 PM

Okay, i gotcha. Here's a working example. Its a function I have placed in functions.php. It hooks into the loop, rather than having to edit the loop itself, although you could do that too by editing template.postloop.php. Its for a post type of "movie" and displays the contents of several custom fields created with the plugin Advanced Custom Fields, but you could use any worpdress tags like the_permalink, the_title, the_excerpt etc. The custom content comes after the post content, but you could use different hooks to place it wherever you need to.

Please Login or Register to see this Hidden Content


Hope this helps.

#12 raquel_p

raquel_p

    Advanced Member

  • Members
  • 57 posts
  • Framework Version:2.3
  • Country: Country Flag

Posted 10 August 2011 - 01:41 PM

Kastellic,

His example helped very much. I got success by entering the values ??‹??‹of the Custom fields, using the More Fields, with:

Please Login or Register to see this Hidden Content


But I found it strange that the code below, which is native to Wordpress, does not work with PlatformPro:

Please Login or Register to see this Hidden Content


Thanks anyway. I'm trying to enable my project, and it is not possible to build functions with the code of More Fields, because it is a direct command to echo. I need the:

Please Login or Register to see this Hidden Content

working in PlatformPro.

Do you know any alternative to this problem?
It seems that using the Advanced Custom Fields, as in your example, is bypassing the problem.

The strange thing is that the get_the_terms_list works perfectly.

Ps. I entered my code in functions.php, the PlatformBase.

#13 raquel_p

raquel_p

    Advanced Member

  • Members
  • 57 posts
  • Framework Version:2.3
  • Country: Country Flag

Posted 11 August 2011 - 01:08 PM

Is solved!
In any case, using the More Fields, Advanced Custom Fields or any of them. You can get the output by entering:

Please Login or Register to see this Hidden Content


The example of Kastellic would look like this:

Please Login or Register to see this Hidden Content


It worked perfectly in my project.

I hope this example will help other people.

#14 raquel_p

raquel_p

    Advanced Member

  • Members
  • 57 posts
  • Framework Version:2.3
  • Country: Country Flag

Posted 11 August 2011 - 07:50 PM

Correcting:

Please Login or Register to see this Hidden Content