Tag Info

New answers tagged

2

If you want to use get_attached_media(), you can try for example: if( has_post_thumbnail() ) { the_post_thumbnail(); } else { $imgs = get_attached_media( 'image' ); if( count( $imgs ) > 0 ) { $img = array_shift( $imgs ); echo wp_get_attachment_image( $img->ID, 'thumbnail' ); } } to display one of the attached ...


0

If you want to get image links frop category and subcategories you should use this: global $wpdb; $id = 60; // your cat id $myrows = $wpdb->get_results( "SELECT p2.ID, p2.guid ". "FROM $wpdb->posts as p1, $wpdb->posts as p2, $wpdb->term_relationships as tr, $wpdb->term_taxonomy as tt ". "WHERE ". "((tr.term_taxonomy_id = $id ...


1

This should work for the rel attribute: /** * Create a rel attribute from the image categories * * @see http://wordpress.stackexchange.com/a/158024/26350 */ add_filter( 'get_image_tag', function( $html, $id ) { $rel = array(); foreach( (array) get_the_category( $id ) as $cat ) { $rel[] = $cat->slug; ...


0

Found out how to do it, I added the following in content.php. I added the second elseif statement and simple put the word Document in there before it displays the title of the page. if ( is_single() ) { the_title( '<h1 class="entry-title">', '</h1>' ); } elseif (get_post_type() == 'attachment' ) { the_title( '<h1 ...


0

The answer was to assign a count to each attachment: $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID, 'order_by' => 'menu_order', 'order' => 'DESC' ); $attachments = get_posts( $args ); if ( $attachments ) { $count = 0; foreach ...


0

A bit of background to make sure we are in sync: Uploading an image means that you create a new post (of type attachment) in WordPress database and you create a few image files in WordPress file system (one file per size) Attaching to a post means that you mark the (hereabove) attachment post as child of this post. Meaning that an attachment can be only ...


0

wordpress sucks in keeping media<=>content relationships. Part of the problem is that by default all media are public once they are uploaded and you have no way to know where are they are being used. Just because an image is not referenced anymore in its original post doesn't mean that it is not referenced at any other place (sidebar widget?) or maybe by ...


3

This should hopefully do the trick: /** * Append the image categories to the current image class. * * @see http://wordpress.stackexchange.com/a/156576/26350 */ add_filter( 'get_image_tag_class', function( $class, $id, $align, $size ) { foreach( (array) get_the_category( $id ) as $cat ) { $class .= ' category-' . ...


0

WordPress is engineered exclusively to reside in web-accessible folders, unlike many less user-centric web frameworks, which separate locations of private (code, etc) and public (assets). Making filenames hard to guess is about as good as it gets with normal workflow. To have this really tight you would need completely custom workflow with files places ...


0

The easiest solution is to not publish critical information in the future. When you need to follow some regulations or contracts then you don't want to depend upon wordpress or your server stack to not have any bugs which will disclose the info too early or too late. Wordpress is a great software but it is just not good enough (and same goes for the server ...


1

You could do like this: function image_tag_class($class) { $class .= ' my-custom-class'; return $class; } add_filter('get_image_tag_class', 'image_tag_class' ); in case you wanna know more about actions and hooks. Difference Between Filter and Action Hooks? add_filter add_action



Top 50 recent answers are included