WORDPRESS:自定义字段是我的作品集的解决方案吗?

发布于 2024-10-15 18:11:37 字数 395 浏览 2 评论 0原文

以下是我想要做的事情的简要说明:

我的主页将包含大约 12 个缩略图,其中包含标题、简短描述,也许还有网址(排列为 3 x 4 或其他)。我希望这些条目中的每一个都链接到我的 single.php 页面,该页面将显示有关每个项目的更多详细信息,其中多个较大的图像文件将在项目描述的右侧显示标题。

我认为解决此问题的最佳方法是在主页上使用“特色图像”作为缩略图显示,该图像现在似乎可以正常工作,但我一直在尝试找出用于其他图像的自定义字段(图像 1、图像 2、图像 3)。我想不通。我希望能够从一个屏幕输入新作品集的所有内容和图像。可能的?

这可行吗?如果是这样,怎么办?自定义字段此时让我非常困惑,即使在网上阅读了大量有关它的文章之后也是如此。

我真的很感激一些意见!我似乎无法破解这个问题,这有点令人沮丧。 :P

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 whatever). I want each of these entries to link to my single.php page which will show more details about each project, with multiple larger image files that will display with captions to the right of the project description.

I'm thinking the best way to approach this would be to use the 'featured image' for the thumbnail display on the homepage which seems to be working now, but I've been trying to figure out Custom Fields to use for my other images (image1, image2, image3). I can't figure it out. I want to be able to enter all the content and images for a new portfolio piece from one screen. Possible?

Is this doable? If so, how? The Custom Fields are confusing me really badly at this point, even after reading tons of articles online about it.

I'd really appreciate some input! I can't seem to crack this and it's getting a bit frustrating. :P

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猥︴琐丶欲为 2024-10-22 18:11:37

自定义字段是每个帖子的键值对。所以你当然可以将它们用于此目的。例如,您可以将自定义字段完全按照建议命名:image1、image2 等。请注意,自定义字段的通用性质确实使这至少有点尴尬,但它可能仍然是您的最佳选择。

这些关键字必须在某个地方进行处理,听起来好像您的 single.php 就是执行此操作的地方。本质上,您的 single.php 是一个自定义帖子模板,因此您可以提取自定义字段数据并根据需要呈现它。您需要编写 PHP 代码来执行此操作,并熟悉 WordPress 函数参考

get_post_meta 函数可能是最相关的函数,但请参阅主要参考中的其他函数。

你想做的事并不难,但第一次很难做到。这是因为您将在此过程中学习 WordPress 的各种细微差别。

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.

时光瘦了 2024-10-22 18:11:37

我真的很理解你的处境。事实上,我之前已经做过相同的插件,您必须在一篇文章和一个自定义字段中附加几张图像。这是我的解决方案:

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

如果有帮助,请告诉我。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文