tag content for the Tag Gallery and Single Image pages * * @param string The default page title * @param string $sep How to separate the various items within the page title * @param string $seplocation Optional. Direction to display title, 'right'. * * @return string updated title value */ function mla_wp_title_filter( $title, $sep, $seplocation ) { $sep = " {$sep} "; if ( is_page() ) { $page = single_post_title( '', false ); /* * Match specific page titles and replace the default, page title, * with more interesting term or file information. */ if ( 'Tag Gallery' == $page ) { $taxonomy = isset( $_REQUEST['my_taxonomy'] ) ? $_REQUEST['my_taxonomy'] : NULL; $slug = isset( $_REQUEST['my_term'] ) ? $_REQUEST['my_term'] : NULL; if ( $taxonomy && $slug ) { $term = get_term_by( 'slug', $slug, $taxonomy ); return $term->name . $sep; } } elseif ( 'Single Image' == $page ) { $post_id = isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : 0; if ( $post_id ) { $file = get_attached_file( $post_id ); $pathinfo = pathinfo( $file ); return $pathinfo['basename'] . $sep; } } } // is_page return $title; } add_filter( 'wp_title', 'mla_wp_title_filter', 10, 3 ); /** * Generate a taxonomy- and term-specific [mla_gallery] * * @param array Attributes of the function: taxonomy, term * * @return void echoes HTML
and tags
*/
function mla_tag_gallery( $attr = NULL ) {
/*
* Make sure $attr is an array, even if it's empty
*/
if ( empty( $attr ) ) {
$attr = array();
} elseif ( is_string( $attr ) ) {
$attr = shortcode_parse_atts( $attr );
}
/*
* Create the PHP variables we need
*/
extract( shortcode_atts( array(
'taxonomy' => 'attachment_tag',
'term' => ''
), $attr ) );
/*
* Convert to objects for validation and labels
*/
$taxonomy = get_taxonomy( $taxonomy );
$term = get_term_by( 'slug', $term, $taxonomy->name );
if ( empty( $taxonomy ) ) {
$output = __( 'Taxonomy does not exist.', 'mla-child-theme' );
}
elseif ( empty( $term ) ) {
$output = __( 'Term does not exist.', 'mla-child-theme' );
}
else {
/* translators: 1: term name, 2: taxonomy label */
$output = ' ' . do_shortcode( sprintf( '[mla_gallery %1$s="%2$s" post_mime_type=all mla_nolink_text="No items found" ]', $taxonomy->name, $term->slug ) . " and tags
*/
function mla_paginated_term_gallery( $attr = NULL ) {
global $wpdb;
/*
* Make sure $attr is an array, even if it's empty
*/
if ( empty( $attr ) ) {
$attr = array();
} elseif ( is_string( $attr ) ) {
$attr = shortcode_parse_atts( $attr );
}
/*
* Create the PHP variables we need
*/
extract( shortcode_atts( array(
'page' => NULL,
'taxonomy' => 'attachment_tag',
'term' => '',
'post_mime_type' => 'all',
'posts_per_page' =>10,
'current_page' => 1
), $attr ) );
/*
* Convert to objects for validation and labels
*/
$taxonomy = get_taxonomy( $taxonomy );
$term = get_term_by( 'slug', $term, $taxonomy->name );
if ( empty( $taxonomy ) ) {
echo __( 'Taxonomy does not exist.', 'mla-child-theme' );
return;
}
elseif ( empty( $term ) ) {
echo __( 'Term does not exist.', 'mla-child-theme' );
return;
}
$offset = absint( $current_page - 1 ) * $posts_per_page;
if ( 'all' == strtolower( $post_mime_type ) ) {
$count = $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $wpdb->term_relationships . ' WHERE ( term_taxonomy_id = ' . $term->term_taxonomy_id . ' )' );
$posts = implode( ',', $wpdb->get_col( 'SELECT object_id FROM ' . $wpdb->term_relationships . ' WHERE ( term_taxonomy_id = ' . $term->term_taxonomy_id . ' ) LIMIT ' . $offset . ', ' . $posts_per_page ) );
} else {
/*
* $posts contains all post types, so we further limit the results to select attachments of the
* desired MIME type, then apply the limit criteria.
*/
$mime_where = wp_post_mime_type_where( $post_mime_type, 'p' );
$posts = implode( ',', $wpdb->get_col( 'SELECT object_id FROM ' . $wpdb->term_relationships . ' WHERE ( term_taxonomy_id = ' . $term->term_taxonomy_id . ' )' ) );
$count = $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $wpdb->posts . ' AS p WHERE ( p.ID IN ( ' . $posts . ' )' . $mime_where . ')' );
$posts = implode( ',', $wpdb->get_col( 'SELECT p.ID FROM ' . $wpdb->posts . ' as p WHERE ( p.ID IN ( ' . $posts . ' )' . $mime_where . ') LIMIT ' . $offset . ', ' . $posts_per_page ) );
}
$href = empty( $page ) ? '{+link_url+}' : "{+site_url+}{$page}";
/* translators: 1: term name, 2: taxonomy label */
$output = ' ' . do_shortcode( sprintf( '[mla_gallery ids="%1$s" post_mime_type="%2$s" mla_paginate_current=1 mla_nolink_text="No items found" update_post_term_cache="false" mla_link_href="%3$s?post_id={+attachment_ID+}"]', $posts, $post_mime_type, $href ) . " and tags
*/
function mla_custom_terms_list( $ID, $attr = NULL ) {
/*
* Make sure $attr is an array, even if it's empty
*/
if ( empty( $attr ) ) {
$attr = array();
} elseif ( is_string( $attr ) ) {
$attr = shortcode_parse_atts( $attr );
}
/*
* Create the three PHP variables we need
*/
extract( shortcode_atts( array(
'site_url' => site_url(),
'page_path' => '/tag-gallery/',
'taxonomy' => 'attachment_tag',
), $attr ) );
/*
* Get the terms associated with the current attachment.
* Return nothing if there are no terms associated with the attachment.
*/
$terms = get_the_terms( $ID, $taxonomy );
if ( empty( $terms ) ) {
return '';
}
/* translators: 1: taxonomy slug */
$output = ' ' . sprintf( '%6$s', $site_url, $page_path, $taxonomy, $term->slug, $title, $term->name ) . "' . sprintf( __( 'Gallery for term "%1$s" in taxonomy "%2$s"', 'mla-child-theme' ), $term->name, $taxonomy->labels->name ) . '
';
$output .= ',
' . sprintf( __( 'Gallery for term "%1$s" in taxonomy "%2$s"', 'mla-child-theme' ), $term->name, $taxonomy->labels->name ) . '
';
$output .= ',
' . sprintf( __( 'Terms list for taxonomy: %1$s', 'mla-child-theme' ), $taxonomy ) . '
';
/* translators: 1: term name */
$title = sprintf( __( 'Gallery for %1$s', 'mla-child-theme' ), $taxonomy );
foreach ( $terms as $term ) {
$output .= ',