Support » Fixing WordPress » Show attachments if name is the same as category

  • Hello,
    I am trying to get attachments to show on a category page that are appropriate to that category, to do this I am naming them with a ‘prefix’ I guess of that pages category so for example;
    the category is named: Sunny Photos
    and an attachment might be named: Sunny Photos Photo Number 1.
    So I am trying to check a substring against the category title and if that works then show the attachment properties (title link etc)
    My current code is :

    				$args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => null );
    				$attachments = get_posts( $args );
    				if ($attachments) {
    					foreach ( $attachments as $post ) {
    						if(single_cat_title() == substr(the_title(), 0, $catlength)){
    						the_attachment_link($post->ID, false);

    this still seems to return all of the attachments from the whole site rather then the ones specified for the category, any help would be greatly appreciated

  • The topic ‘Show attachments if name is the same as category’ is closed to new replies.