Archived

This topic is now archived and is closed to further replies.

  • 0

Resolved Adding Custom Fields Code To Functions.php

Question

Posted · Report post

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

Share this post


Link to post
Share on other sites

12 answers to this question

Posted · Report post

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

Posted · Report post

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

Posted · Report post

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

Posted · Report post

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

Posted · Report post

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

Share this post


Link to post
Share on other sites

Posted · Report post

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

Posted · Report post

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

Share this post


Link to post
Share on other sites

Posted · Report post

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

Posted · Report post

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

Posted · Report post

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

Share this post


Link to post
Share on other sites

Posted · Report post

The topic was marked as resolved.

Share this post


Link to post
Share on other sites