WORDPRESS: Is Custom Fields the solution for my portfolio?

前端 未结 2 976
予麋鹿
予麋鹿 2021-01-27 06:17

Here\'s a brief explanation of what I\'m trying to do:

My homepage will have about 12 thumbnail images with title, short description, maybe web url (arranged 3 x 4 or wh

相关标签:
2条回答
  • 2021-01-27 06:41

    Custom fields are per post key-value pairs. So you could certainly use them for this purpose. For instance, you could have custom fields named exactly as suggested: image1, image2, etc. Note that the generic nature of custom fields does make this at least a little awkward, but it is probably still your best option.

    Those keywords must be processed somewhere, and it sounds as if your single.php is the place to do it. Essentially your single.php is a custom post template, so you can extract the custom field data and render it as you wish. You will need to write PHP code to do this, and be comfortable in reading the WordPress function reference.

    The get_post_meta function is probably the most relevant one, but see the others on the main reference.

    What you want to do isn't difficult, but is hard to do the first time. That's because you will be learning all sorts of little nuances of WordPress along the way.

    0 讨论(0)
  • 2021-01-27 06:48

    I really understand your situation. In fact i have already done the same plugin before where you have to attach several images in one post and in one custom field. Here is my solution:

    $images = trim(get_post_meta($post->ID,'images',true)); 
    $images_array = explode(',',$images);
    foreach($images_array as $i){
       echo '<img src="'.$i.'"/>';
    }
    

    Let me know if that helps.

    0 讨论(0)
提交回复
热议问题