Show attachments if name is the same as category (1 post)

  1. andykarasek02
    Posted 2 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic