php 创建自定义wordpress图库输出
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 创建自定义wordpress图库输出相关的知识,希望对你有一定的参考价值。
<?php
function _revise_post_gallery( $output, $attr ) {
global $post;
if ( isset( $attr['orderby'] ) ) {
$attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
if ( ! $attr['orderby'] ) {
unset( $attr['orderby'] );
}
}
extract( shortcode_atts( array(
'captiontag' => 'dd',
'columns' => 3,
'icontag' => 'dt',
'id' => $post->ID,
'include' => '',
'itemtag' => 'dl',
'order' => 'ASC',
'orderby' => 'menu_order ID',
'size' => 'thumbnail',
'exclude' => '',
), $attr ) );
$id = intval( $id );
if ( 'RAND' == $order ) {
$orderby = 'none';
}
if ( ! empty( $include ) ) {
$include = preg_replace( '/[^0-9,]+/', '', $include );
$_attachments = get_posts( array(
'include' => $include,
'order' => $order,
'orderby' => $orderby,
'post_mime_type' => 'image',
'post_status' => 'inherit',
'post_type' => 'attachment',
) );
$attachments = array();
foreach ( $_attachments as $key => $val ) {
$attachments[ $val->ID ] = $_attachments[ $key ];
}
}
if ( empty( $attachments ) ) {
return '';
}
// Here's your actual output, you may customize it to your needs
$output = '<div class="grid-container">';
$count = 0;
// Now you loop through each attachment
foreach ( $attachments as $id => $attachment ) {
$img = wp_get_attachment_image_src( $id, 'medium' );
$output .= '<a href="" class="modal-trigger" data-index="' . absint( (int) $count ) . '" data-target="#modal-gallery">';
$output .= '<img src="' . esc_url( $img[0] ) . '" width="' . absint( (int) $img[1] ) . '" height="' . absint( (int) $img[2] ) . '" alt="' . esc_html__( 'Click to View Larger', 'apracticalwedding' ) . '" class="gallery-item" />';
$output .= '</a>';
$count++;
}
$output .= '</div>';
return $output;
}
add_filter( 'post_gallery', '_revise_post_gallery', 10, 2 );
以上是关于php 创建自定义wordpress图库输出的主要内容,如果未能解决你的问题,请参考以下文章
php 创建自定义wordpress图库输出
PHP 带有自定义帖子类型和自定义分类的WordPress图库页面
如何在 wordpress 中显示自定义帖子类别名称列表
在Wordpress上使用ACF上的自定义字段时找不到“图库”字段类型
markdown WordPress的自定义图库格式(使用Bootstrap v4网格)。
markdown WordPress的自定义图库格式(使用Bootstrap v3网格)。