WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom Fields (9 posts)

  1. Debb477
    Member
    Posted 5 years ago #

    I have managed to create a Custom Field on my post but how do I get it to show up on my page. I've read and reread the Codex instructions but it is all Greek to me. Pls help!

  2. mores
    Member
    Posted 5 years ago #

    you need to edit your theme files for the custom fields to show up, they don't magically appear.
    So, grab notepad or some other texteditor and start coding :)

  3. Debb477
    Member
    Posted 5 years ago #

    That's the part that's confusing, I thought Word press was user friendly but it appears you need some training in coding!

  4. sojweb
    Member
    Posted 5 years ago #

    Well, yes, to the extent that there's no way for your theme to know which custom field to pull and what to do with it. You might also find themes with custom field support built in, or I'm sure there are widgets/plugins out there that handle them in some way.

  5. mores
    Member
    Posted 5 years ago #

    WordPress is user friendly out-of-the-box, once you start customizing, you need code. But even then it's simple, most of the time, as long as you have basic copy/pasting skills and know how to use FTP. Or actually, you can use the theme editor built-in to WordPress to add stuff like that.

    Explain why you need custom fields? Maybe there are simpler solutions that won't require you to code.

  6. Debb477
    Member
    Posted 5 years ago #

    I want to be able to add a section Currently Reading; Today's Mood as explained in Codex - Using Custom Fields. My problem is knowing where to insert the template tag.

  7. t31os
    Member
    Posted 5 years ago #

    If you want it on the single post page then single.php, if you want it elsewhere then also update the appropriate template files..

    Which depends which files exist for your theme, check what you have and update the necessary files, for the cases you want it to appear..
    http://codex.wordpress.org/images/1/18/Template_Hierarchy.png

  8. Dunkkan
    Member
    Posted 5 years ago #

    An example of custom field :

    <div class="loopinindex">
    
    		<!-- starting the loop -->
    
    		<?php
    		if (have_posts()) :
    		while (have_posts()) :
    	        the_post();
    		?>
    
    		<?php the_title(); ?>
    		<?php the_content(); ?>
    
    		<!-- pulling the custom field -->
    
    		<?php
    		$music = get_post_meta($post->ID, "listening", true); ?>
    
    		<!-- printing the custom field -->
    
    		<?php echo $music ; ?>
    
    		<?php endwhile;
    		endif;
    		?>
    </div>

    listening being the name of the custom field.
    Hope that helps.

  9. Ryan Paul
    Member
    Posted 5 years ago #

    You could also do the following. I'll assume the custom field is called 'Currently Reading'...

    <?php $curread = get_post_custom_values("Currently Reading"); if ( $curread != '' ) { ?>Currently Reading: <?php echo $values[0]; ?><?php } ?>

    <?php the_content(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic