Jump to content
quinntinm

Adding Custom Fields Code To Functions.php

Recommended Posts

quinntinm    4
quinntinm

Hi there.

I played around with custom fields on a temporary site, added all the necessary code to the functions.php file and it all worked fine except when i added it to the base file functions.php - the page in the wp-admin / editor just went white / blank.

I am not sure what i did wrong, can anyone help.

This is the code i added:

/**

* ================================= QUINTIN

* The function for custom post types added here

* ----------------------------------------------------

*/

add_action('init', 'register_rc', 1); // Set priority to avoid plugin conflicts


	function register_rc() { // A unique name for our function

   	 $labels = array( // Used in the WordPress admin

   		 'name' => _x('Films', 'post type general name'),

   		 'singular_name' => _x('Film', 'post type singular name'),

   		 'add_new' => _x('Add New', 'Film'),

   		 'add_new_item' => __('Add New Film'),

   		 'edit_item' => __('Edit Film'),

   		 'new_item' => __('New Film'),

   		 'view_item' => __('View Film '),

   		 'search_items' => __('Search Film'),

   		 'not_found' =>  __('Nothing found'),

   		 'not_found_in_trash' => __('Nothing found in Trash')

   	 );

   	 $args = array(

   		 'labels' => $labels, // Set above

   		 'public' => true, // Make it publicly accessible

   		 'hierarchical' => false, // No parents and children here

   		 'menu_position' => 5, // Appear right below "Posts"

   		 'has_archive' => 'Films', // Activate the archive

   		 'supports' => array('title','editor','comments','thumbnail','custom-fields'),

   	 );

   	 register_post_type( 'film', $args ); // Create the post type, use options above

Edited by Simon_P
Added code tags (see edit history)

Share this post


Link to post
Share on other sites
Simon    247
Simon

You are missing the closing } at the end of your function, turning on WP_DEBUG in wp-config.php would have helped.

Share this post


Link to post
Share on other sites
quinntinm    4
quinntinm

Now if i was a progrmmer i might have spotted something as silly as that, thanks Simon_P.

Ca

n you suggest the best way to tackle adding custom fields? Using the built in custom fields or a specific plugin to do it.

This is for a client to edit and i want to make it as easy as possible.

Thanks.

Quintin.

Share this post


Link to post
Share on other sites
quinntinm    4
quinntinm

Thanks Simon, will defiitly check it out.

A last question for now, how do i hide this entire line if there is nothing added into the field in the admin?

<h4 class="filmhdrnext">Duration:</h4> <?php echo $film_duration ?>

thanks.

Share this post


Link to post
Share on other sites
Simon    247
Simon

Use some logic...

<?php if ( isset( $film_duration ) ) printf( '<h4 class="filmhdrnext">Duration: </h4>%s', $film_duration ); ?>[/CODE]

Share this post


Link to post
Share on other sites
quinntinm    4
quinntinm

Hey Simon, it still displayes the title "Duration"...

Share this post


Link to post
Share on other sites
Simon    247
Simon

Try this then...

<?php if ( '' != $film_duration ) printf( '<h4 class="filmhdrnext">Duration: </h4>%s', $film_duration ); ?>[/CODE]

Share this post


Link to post
Share on other sites
quinntinm    4
quinntinm

Magic, thank you so much for your help - really appreciate it!

Share this post


Link to post
Share on other sites
quinntinm    4
quinntinm

Simon, i have another question.

Your solution <?php if ( '' != $film_country ) printf( '<h4 class="filmhdr">Country</h4>%s', $film_country ); ?> worked for all the fields except the url.

How would i do it for this - when i tried it, i keep getting errors.

<h4 class="filmhdr">Trailer</h4> <a class="lbpModal cboxElement" href="http://www.youtube.com/watch?v=<?php echo $film_link ?>">View the clip</a>

Thanks.

Share this post


Link to post
Share on other sites
Simon    247
Simon

Same

<?php if ( '' != $film_country ) printf( '<h4 class="filmhdr">Trailer</h4><a class="lbpModal cboxElement" href="http://www.youtube.com/v/%s">View the clip</a>', $film_link ); ?>[/CODE]

Share this post


Link to post
Share on other sites
quinntinm    4
quinntinm

Cool, thank you - i see how that works now.

Share this post


Link to post
Share on other sites
mackenzie    12
mackenzie

The topic was marked as resolved.


Mackenzie - PageLines Help Desk

The Centsible Family - Writer, Photographer and Coffee Addict

---------------------------------------------------

Kindly search this forum and read the documentation before posting. It will help you resolve many issues.

For CSS help be sure to check out W3Schools first and be sure to download FireBug for FireFox for troubleshooting.

Share this post


Link to post
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


  • Similar Content

    • janpeeters
      By janpeeters+
      Over the last month I had extensive communications with the developer of the (premium) Anything Boxes section (in Pagelines store) (Adam Munns) and the developer of the WP Polylang Multilingual plugin (Frederic Demarle).
       
      This was because the following problem occurred:
      Anything Boxes showed all posts of two languages (Dutch and English) on the respective static frontpages for each language. It should of course have filtered posts for Dutch language on the Dutch frontpage and English on the English frontpage.
       
      The solution to this problem was simple in the end. When duplicating a page for use in another language the settings for Anything Boxes were not copied to the new page and I should have set these settings manually again on the new page. I wasn't aware of this, but it makes sense. Because of this the pages didn't know how to differentiate between posts from different languages.
       
      The dev of Polylang told me that Polylang is currently smart enough to synchronize metas like Featured images and page templates but it does not work out of the box with metas created by plugins and themes but (according to Frederic) it is rather easy to add them in the list using the filter 'pll_copy_post_metas'.
      He mentions that he is not sure that these 'PageLines Meta Settings' are stored in post meta but that would make sense according to him. He asks if the Pagelines dev team will be interested to support this feature in the future.
       
      I'm also wondering if you will consider adding Polylang translation support for manually editable strings like the 'Read more…' strings in Pagelines Settings.
       
      Well that's of course up to you but I thought to let you know to be able to take this into consideration. I also post this for other users in case they experience the same kind of trouble and are looking for an answer.
       
      Best regards,
      Jan Peeters
    • bankrollbuilder
      By bankrollbuilder
      I used a custom hook to put a banner ad in my header. It works but its not in the right position. it is centered and above my logo and I would like to float it to the right of my logo in the header. heres the link: http://shaboopie.com/shaboopie-wp/free-logos-pg1/

      thanks.

      Dan B.
    • starlit
      By starlit
      Can one have two hero sections on one page?

      I want a landing page which leads/advertises two subpages.

      Or is there another option?

      Please help.

      THANK YOU
    • hutruk
      By hutruk
      Hi!

      I am using the shortcodes for tabs, as described in the documentation.

      When I insert the following code:


      [pl_tabs][pl_tabtitlesection type="tabs"] [pl_tabtitle number="1"]Title 1[/pl_tabtitle] [pl_tabtitle number="2"]Title 2[/pl_tabtitle] [/pl_tabtitlesection] [pl_tabcontentsection] [pl_tabcontent active="yes" number="1"] Lorem ipsum dolor sit amet, consectetur adipiscing elit [/pl_tabcontent] [pl_tabcontent number="2"] Lorem ipsum dolor sit amet, consectetur adipiscing elit [/pl_tabcontent] [/pl_tabcontentsection] [/pl_tabs]

      I get a strange output (in the attachment).

      Any ideas?

      Thanks in advance!

    • MooiWeb
      By MooiWeb
      Hello,

      I would like to align my qtranslate with my breadcrumb so that the flags are on the same hight.
      I'm aware of putting a code in the custom css and tryed severall codes from your site but for now, no succes

      The site i'm working on is http://nieuw.vazdias.nl

      Thx,
      Edwin



×