Can this forum help with Wordpress?

I’m having difficulty getting an answer there to what seems to me to be a simple question.

If I get a yes, I’ll start a new post on topic.

Thanks in advance!

WordPress 3’s new custom post types feature should go a long way towards making custom content types heaps easier.

I’m excited!

Very cool. That might even work for this, but raena’s solution was perfect this go-round. Thanks regardless.

candlebain & anybody else looking to do something similar, I suggest you check out the Magic Fields plugin: It makes life extremely easy to create custom write panels that include the ability to upload files (pdfs, images, word documents, whatever) and have them associated to a particular custom field (postmeta data). It also includes handy functions for retrieving them and displaying those in your template

Hey, awse! :smiley:

Let us know if you’re having any trouble with it.

Thanks! I’ll give it a shot.

It works! You’re awesome. Thanks so much.

If I’m understanding right, what you’ve been doing is posting stuff under categories, and attaching stuff to those posts. Now you want to make a list of all the attachments from the posts under a given category, right?

If that’s right, then what I’d do is create a new loop to grab all the posts from the category, and then use your get_posts stuff in there.

Here’s a function for you that spits out a list of all the attachments belonging to the posts in a category.

function get_attachments_by_cat($cat) {
// make a new Loop that pulls posts from the specified category

// do the Loop

if ( have_posts() ) : while ( have_posts() ) : the_post();

// then let's set up for those attachments

	$args = array(
		'order'          => 'ASC',
		'post_type'      => 'attachment',
		'post_parent'    => get_the_ID(),
		'post_status'    => null,
		'numberposts'    => -1,
	$attachments = get_posts($args);

        // do we have some attachments? 
	if ($attachments) {

           // ok, let's do some markup prep
	   echo '<h3>'. get_the_title() . '</h3>';
	   echo '<ul>';
               // now let's build a list item for each attachment
           foreach ($attachments as $attachment) {
	       echo '<li><h4>';
	       echo wp_get_attachment_link($attachment->ID, false, false, false);
	       echo '</h4>';
	       echo wp_get_attachment_link($attachment->ID, 'thumbnail', true, true);
	       echo '</li>';
	  echo '</ul>';

endwhile; else:
 // there are no posts in this cat.
// we're done with that query

Now you could call on it like so in your templates.


(where 88 is the category number you want).

Does that sort of help?

It’s a bit query-intensive :\

I did not get that you wanted to get files from WP’s media library.
That is another story and won’t work with what I gave you.

For that, the information here will be of use:

An easier route would be to look for a plugin that allows you to easily manage your media library and output results as needed:

Sorry, can’t be of more help there. I’ve worked a lot with custom fields but not the media library.

Thanks anyways. I’m starting to feel like this isn’t possible. I’m going to rethink my plans.

Well once you upload a file, it’s stored in your “Media Library”

You could create a page/post and then attach each file. Might be a little bit of work - and surely there’s an easier way to do it (possibly with custom fields)

Yeah…I’m sure kohoutek has got it clear in his mind. I haven’t been able to connect the dots. When he’s back on, I’ll be curious to see what he comes up with.

Thanks! Here goes:

I’m trying to build a WP-driven site for my Rock History college classes I teach. I intend to post pdfs of lectures, Word .doc files, and audio for 3 different classes. I want to post the media in Blog-style posts, but then have a master page for each course that contains all posted attachments, but not the blog-post text. Currently, it makes sense to me to label posts with a Category for the class its for.

So, is there a way to make a template that pulls only the attachments from a single category? like category-rock-1.php? And how would I do it?

I’ve tried using get_posts(), but I keeping getting either all attachments site-wide, or nothing at all. get_children() was also suggested but I couldn’t get that to work at all. I’m in over my head I think.

The easiest thing I can think of is just to use Categories.

Class 1
Class 2
Class 3

When you’re creating a post - you’d just assign it to the specific category.

WordPress has already built in the ability to attach files to posts.

You’d also need to set up your Permalinks. So, you’d tell your first class to go to and it instantly takes them to that category, with the posts relative to their class.

Ok. I think I understand. I’ll experiment and then check back once I have something working.

Thanks for your help.

That’s great! And when you get stuck, do come back and we’ll get it sorted.

Instead of

'post_parent' => null


'post_parent' => $post->ID

You’d create a post and attach the attachments you want to appear on that post (the master page or post), and it will only pull attachments with that post ID

Another thing you can try is instead of category name, using the category ID.

'category' => '1',

You’ll need to read up on Custom Fields as it’s important that you understand what this function does and how it works:

When you have read it, you’ll understand how to implement it.

Basically, you can sort by the get_post_meta() function. More on that in the link I posted above.

This is what I was thinking originally. How would you then collect all the attachments from one category into a single page?

Then how would I sort by class?