Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #349477

    Hi All,

    I am changing the theme from twenty ten to Enfold. I had some 4 Custom Fields for each post which I displayed under the post title in twenty ten. How can I add them to Enfold so that they are displayed under the post title in Enfold?

    regards,

    #349773

    Hi TheElear!

    Open up /enfold/includes/loop-index.php and on line 132 you should see this.

    echo $title;
    

    Add this on the next line.

    echo get_post_meta( $the_id, 'key', true );
    

    And change “key” with whatever key you have set for your custom field.

    Best regards,
    Elliott

    #350247

    Hi Elliot,

    Shall I copy loop-index.php file to enfold-child theme folder?

    regards,
    Peter

    #350368

    Hi!

    Yes you can do that. Let us know if you have any other questions.

    Best regards,
    Elliott

    #350539

    Hi there,

    I have copied the file loop-index.php to the child theme folder added the following code and it does not work – nothing is displayed:

    echo get_post_meta( $the_id, 'key', true );

    I have 4 custom fields in each language. I need to display them in a specific order under the post title on all pages where t=posts are (eg. blog roll, single post, specific category/tag post)

    Below is the code I used in twenty ten a couple of years ago. It illustrates the principle:

    <div class="pprow">
    		<?php $myid = $post->ID; // Assign this using a variable, or however you were before, eg. $post->ID
    
    		$data = $wpdb->get_results("
    		SELECT * FROM $wpdb->postmeta WHERE post_id = $myid
    		AND meta_key NOT LIKE '\_%'
    		ORDER by (CASE WHEN meta_key = 'Composed in' THEN 0
    				WHEN meta_key = 'Duration' THEN 1
    	       			WHEN meta_key = 'Instrumentation' THEN 2
    	       			WHEN meta_key = 'Movements' THEN 3 
    	       			WHEN meta_key = 'Rok' THEN 4
    	       			WHEN meta_key = 'Czas' THEN 5
    	       			WHEN meta_key = 'Instrumentacja' THEN 6
    	       			WHEN meta_key = 'Części utworu' THEN 7 END)
    		"); // meta_key ASC - assign the field to sort e.g. meta_id, meta_key, etc. or specify order using CASE WHEN
    
    		if( !empty( $data ) ) {
    			foreach( $data as $result_object ) {
    				print '<div class="ppmeta-key">';
    				print $result_object->meta_key;
    				print ': ';
    				print '</div><div class="ppmeta-value">';
    				print $result_object->meta_value;
    				print '</div>';
    				print '<br />';
    							}
    					}
    		?>	
    		</div>

    Can you please advise how to implement it in Enfold?

    Many thanks,
    Peter

    • This reply was modified 9 years, 5 months ago by TheElear.
    #350843

    Hey!

    You need to change “key” with whatever key you have set for your custom field.

    This is bordering on custom work though so if you still cannot get it working then it would be best to hire a freelancer to help you out with this customization.

    Regards,
    Elliott

    #350996

    Hi Elliot,

    I think this is misunderstanding. I do not need customization from you and I know that the ‘key’ has to be replaced with my custom field name.

    I have 2 questions:

    1. I need you to tell me which files need to be changed to have custom fields displayed in a post in a blog roll view, single post view, category view. You have said I need to make changes to /enfold/includes/loop-index.php.

    Is this the only file in Enfold theme that is responsible for rendering all the above mentioned post views (blog roll view, single post view, category view, etc.)? Or are there other files that also need editing?

    2. You have also mentioned that I can copy /enfold/includes/loop-index.php to the Enfold-child theme folder. I did that and put echo get_post_meta( $the_id, ‘key’, true ); However this does not work. It is only when changes are made to the file located in the main theme /enfold/includes/ that they work but not in the child-theme.

    So the second question is how to copy /enfold/includes/loop-index.php to the Enfold-child theme folder, so that changes made to this file in the child-theme actually work?

    Hope this explains my problem better than the previous post.

    Many thanks again for your help.
    I really appreciate it.

    regards,
    P

    #351388

    Hi!

    1. Yes the loop-index.php will handle all of those.

    2. Try creating a folder in your child theme called /includes/ and then paste the file there.

    Regards,
    Elliott

    • This reply was modified 9 years, 5 months ago by Elliott.
    #351553

    Hi Elliot,

    That made a trick. I created a folder /includes/ in the child theme and it now works.

    Many thanks,
    Peter

    PS. You can now close this thread.

Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘adding custom fields’ is closed to new replies.