Php 将WordPress生成的内容分成两个分区
我正在尝试将静态HTML站点转换为WordPress主题。目前,存在以下(静态)代码:Php 将WordPress生成的内容分成两个分区,php,jquery,html,wordpress,wordpress-theming,Php,Jquery,Html,Wordpress,Wordpress Theming,我正在尝试将静态HTML站点转换为WordPress主题。目前,存在以下(静态)代码: 职称 职位描述。在essimag nimilib errorum fuga。为自己的精英做准备 如您所见,first col中的所有内容都是基于文本的。第二列中的所有内容都是图像,WordPress只需使用抓取这些内容 是否有一种方法可以将提交的图像排序到单独的div中,例如第二列?我知道jQuery可以做到这一点,但我想知道是否有使用PHP或WordPress的方法。是的,您可以使用以下代码显示上传/附
职称
职位描述。在essimag nimilib errorum fuga。为自己的精英做准备
如您所见,first col
中的所有内容都是基于文本的。第二列中的所有内容都是图像,WordPress只需使用
抓取这些内容
是否有一种方法可以将提交的图像排序到单独的div中,例如第二列
?我知道jQuery可以做到这一点,但我想知道是否有使用PHP或WordPress的方法。是的,您可以使用以下代码显示上传/附加到帖子/页面的任何图像
<div class="second-col">
<?php
// Get all images uploaded/attached to this post/page.
if (
$images = get_posts(
array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'post_mime_type' => 'image',
'orderby' => 'menu_order',
'order' => 'ASC'
)
)
) :
// Loop through the results and display each full-size image.
foreach( $images as $image ) :
echo wp_get_attachment_image( $image->ID, 'full' );
endforeach;
endif;
?>
</div>
get_posts()
是一个WordPress函数,它根据我们传递给它的参数返回一个posts数组。然后,我们循环遍历该数组,并对其中的每个值调用wp\u get\u attachment\u image()
函数wp\u get\u attachment\u image()
是另一个返回HTML图像元素的WordPress函数
为了仅在第二列中显示图像,请不要将其插入post/页面。只需从post/page编辑屏幕上传它们,然后关闭模式窗口并更新post/page。您还可以从媒体库上载图像并将其附加到所需的帖子/页面。是的,您可以使用以下代码显示已上载/附加到帖子/页面的任何图像
<div class="second-col">
<?php
// Get all images uploaded/attached to this post/page.
if (
$images = get_posts(
array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'post_mime_type' => 'image',
'orderby' => 'menu_order',
'order' => 'ASC'
)
)
) :
// Loop through the results and display each full-size image.
foreach( $images as $image ) :
echo wp_get_attachment_image( $image->ID, 'full' );
endforeach;
endif;
?>
</div>
get_posts()
是一个WordPress函数,它根据我们传递给它的参数返回一个posts数组。然后,我们循环遍历该数组,并对其中的每个值调用wp\u get\u attachment\u image()
函数wp\u get\u attachment\u image()
是另一个返回HTML图像元素的WordPress函数
为了仅在第二列中显示图像,请不要将其插入post/页面。只需从post/page编辑屏幕上传它们,然后关闭模式窗口并更新post/page。您还可以从媒体库上载图像,并将其附加到所需的帖子/页面。这里有一个链接:。这就是你的意思吗?你想将包含文本和图像的帖子内容分为两列吗?这里有一个链接:。这就是你的意思吗?你想将包含文本和图像的帖子内容分为两列吗?谢谢。你能解释一下PHP代码中使用的逻辑吗。get_posts()
是内置的WordPress函数吗?@tmyie我在我的答案中添加了一些解释,如果这对你有用,请不要忘记将其标记为已接受的答案:-)谢谢!谢谢你能解释一下PHP代码中使用的逻辑吗。get_posts()
是内置的WordPress函数吗?@tmyie我在我的答案中添加了一些解释,如果这对你有用,请不要忘记将其标记为已接受的答案:-)谢谢!