php修改wordpress库输出(代码片段)

author author     2022-12-12     195

关键词:

/* -------------------------------------- */
/*  Modify Wordpress Gallery Output
/* -------------------------------------- */

add_filter('post_gallery', 'my_post_gallery', 10, 2);
function my_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(
    'order' => 'ASC',
    'orderby' => 'menu_order ID',
    'id' => $post->ID,
    'itemtag' => 'dl',
    'icontag' => 'dt',
    'captiontag' => 'dd',
    'columns' => 3,
    'size' => 'thumbnail',
    'include' => '',
    '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, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));

    $attachments = array();
    foreach ($_attachments as $key => $val) 
      $attachments[$val->ID] = $_attachments[$key];
    
  

  if (empty($attachments)) return '';

  switch ($columns) 
    case '2':
      $col_size = '6';
      break;
    case '3':
      $col_size = '4';
      break;
    case '4':
      $col_size = '3';
      break;
    case '6':
      $col_size = '2';
      break;
    default:
      $col_size = '4';
      break;
  

  // Here's your actual output, you may customize it to your need
  $output = '<div class="row asra-gallery">';

  // Now you loop through each attachment
  foreach ($attachments as $id => $attachment) 
    // Fetch all data related to attachment 
    $img = wp_prepare_attachment_for_js($id);

    // If you want a different size change 'large' to eg. 'medium'
    $url = $img['sizes']['thumbnail_lg']['url'];
    if(empty($url))
      $url = $img['sizes']['full']['url'];
      $height = $img['sizes']['full']['height'];
      $width = $img['sizes']['full']['width'];
    
    else
      $height = $img['sizes']['thumbnail_lg']['height'];
      $width = $img['sizes']['thumbnail_lg']['width'];
    
    
    $alt = $img['alt'];

    // Store the caption
    $caption = $img['caption'];

    $output .= '<div class="col-sm-'.$col_size.' col-xs-6 asra-gallery-item">';
    $output .= '<a href="'.$img['sizes']['full']['url'].'" rel="gallery" class="swipebox" title="'.$caption.'">';
    $output .= "<img src=\"$url\" width=\"$width\" height=\"$height\" alt=\"$alt\" />";
    $output .= "</a>";
    $output .= "</div>";

    // // Output the caption if it exists
    // if ($caption)  
    //     $output .= "<div class=\"orbit-caption\">$caption</div>\n";
    // 
    
  

  $output .= "</div>";

  return $output;

php修改wordpress中的最终输出(代码片段)

查看详情

markdown修改和过滤wordpress媒体库和上传(代码片段)

查看详情

php使用bxslider的wordpress媒体库。(代码片段)

查看详情

php在wordpress中加载javascript库(代码片段)

查看详情

php创建自定义wordpress图库输出(代码片段)

查看详情

php创建自定义wordpress图库输出(代码片段)

查看详情

php在wordpress中手动输出摘录(代码片段)

查看详情

php创建自定义wordpress图库输出(代码片段)

查看详情

php使用帖子附件的wordpress图像库短代码(代码片段)

查看详情

php修改wordpress阅读更多链接(代码片段)

查看详情

php在wordpress生成的页面中加载javascript库(代码片段)

查看详情

php启用wordpress错误日志调试输出到文件(代码片段)

查看详情

php在wordpress中注册并输出一个新菜单(代码片段)

查看详情

php在wordpress中注册并输出一个新菜单(代码片段)

查看详情

php在wordpress中注册并输出一个新菜单(代码片段)

查看详情

php使用一个数据库和一个代码库管理多个wordpress站点(代码片段)

查看详情

php将默认wordpress图像编辑器设置为gd库(代码片段)

查看详情

php发现数据全局被修改的位置,因为wordpress。(代码片段)

查看详情