在wordpress meta框的前端检索photogallery图像值
摘要:
我需要使用自己的html photoGallery,这样做:
- 建议我使用metabox,所以我发现&安装 metabox.io插件。
- 接下来,我使用其网站&生成了高级图像代码。在functions.php上添加了它,以便在后端显示上传器。
- 但是在前端,我很难检索图像的值。
functions.php (metabox.io生成的代码):
add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' );
function your_prefix_register_meta_boxes( $meta_boxes ) {
$prefix = '';
$meta_boxes[] = [
'title' => esc_html__( 'Untitled Field Group', 'online-generator' ),
'id' => 'untitled',
'context' => 'normal',
'fields' => [
[
'type' => 'image_advanced',
'name' => esc_html__( 'Image Advanced', 'online-generator' ),
'id' => $prefix . 'image_advanced_8hswqfsoqai',
'max_file_uploads' => 40,
],
],
];
return $meta_boxes;
}
cms :
这是CMS的结果。创建了一个新的图像字段。 CMS部分完成:
frontend :
然后我从metabox.io&将其放置在index.php 上,但它没有打印什么:
<?php
$images = rwmb_meta( $field_id, array( 'size' => 'thumbnail' ) );
foreach ( $images as $image ) {
echo '<a href="'.$image['full_url'].'"><img src="'.$image['url'].'"></a>';
}
?>
我的问题是:
如何在Frontend上显示Metabox.io插件图像的值(在我自己的HTML内部)?我需要如下:
<div class="col-lg-6 img-grids mt-lg-0 mt-5 pl-lg-4">
<img src="<?php echo get_template_directory_uri().'/assets/images/p1.jpg'; ?>" alt="" class="img-fluid radius-image" />
<img src="<?php echo get_template_directory_uri().'/assets/images/p2.jpg'; ?>" alt="" class="img-fluid radius-image" />
</div>
注意:我不仅在帖子内容中添加画廊,而必须添加画廊作为元盒子的主要原因,是因为我不需要图库显示,而是要显示。在我自己的HTML代码中的前端检索画廊的个体值。
Summary:
I need to use my own html photogallery so to do this:
- I was advised to use MetaBox so I found & installed MetaBox.io plugin.
- Next I generated an Advanced Image code using their website & added it at functions.php for it to show the uploader at Backend.
- But at Front-end I'm having trouble to retrieve the images' values.
Functions.php (MetaBox.io generated code):
add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' );
function your_prefix_register_meta_boxes( $meta_boxes ) {
$prefix = '';
$meta_boxes[] = [
'title' => esc_html__( 'Untitled Field Group', 'online-generator' ),
'id' => 'untitled',
'context' => 'normal',
'fields' => [
[
'type' => 'image_advanced',
'name' => esc_html__( 'Image Advanced', 'online-generator' ),
'id' => $prefix . 'image_advanced_8hswqfsoqai',
'max_file_uploads' => 40,
],
],
];
return $meta_boxes;
}
CMS:
Here's the result at CMS. A new images field is created. CMS part is done:
Frontend:
Then I grabbed this code from MetaBox.io & placed it at index.php but it prints nothing:
<?php
$images = rwmb_meta( $field_id, array( 'size' => 'thumbnail' ) );
foreach ( $images as $image ) {
echo '<a href="'.$image['full_url'].'"><img src="'.$image['url'].'"></a>';
}
?>
My question is:
How to display the MetaBox.io plugin images' values at frontend (inside my own HTML)? I need them as follows:
<div class="col-lg-6 img-grids mt-lg-0 mt-5 pl-lg-4">
<img src="<?php echo get_template_directory_uri().'/assets/images/p1.jpg'; ?>" alt="" class="img-fluid radius-image" />
<img src="<?php echo get_template_directory_uri().'/assets/images/p2.jpg'; ?>" alt="" class="img-fluid radius-image" />
</div>
Note: the main reason I didn't simply add a gallery inside the post content but had to add a gallery as a Meta Box, is because I don't need the gallery to show as is , but to retrieve the gallery individual values at frontend inside my own html code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
谢谢您的建议
因此,在这里,
我们拥有画廊收到的金额。
根据上述代码,在页面模板文件或循环中使用此代码。
rwmb_meta
函数具有三个参数。代码结构:
image_advanced_8hswqfsoqai
get_the_id()
我们现在所处的页面ID。在此页面
/72446616?noredirect = 1 在页面上构建META框,然后发布
将此代码放在
function.php
文件中,您知道它可以在页面上添加一个图像库,并在页面上添加一个图像库
步骤2:在页面模板中显示包含以下
模板名称的同一文件:学生
当然,这仅适用于您在其他地方问相关问题的您(this page)< em> 重要说明
如果您想在圆圈或主页或帖子内部显示,则应该是这种情况。
要显示图像量或任何其他液体,必须在WordPress查询中使用它。
用于WordPress查询循环的示例
thank you for following my advice
So here we are
We have the amount that our gallery receives.
According to the above codes, use this code inside the page template file or inside the loop.
The
rwmb_meta
function has three arguments.code structure:
image_advanced_8hswqfsoqai
get_the_ID()
ID of the page we are in now.To optimize and use the page according to your previous question on this page, I write the following code and please paste it (of course, if you want to work with the page template)
Step 1: Add a function to build the meta box on the page and post
Put this code in the
functions.php
file as you know itNow you can add an image gallery to both the page and the post
Step 2: Display in the page template the same file that contains this
Template Name: students
Of course, this is only for you who asked the relevant question elsewhere (this page)Important note
This should be the case if you want to show inside the circle or the main page or inside the posts.
To display the amount of image or any other liquid, you must use it in the WordPress query.
Example for use in a WordPress query loop