SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 27
  1. #1
    SitePoint Zealot candlebain's Avatar
    Join Date
    May 2009
    Location
    Phoenix, AZ
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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!
    body {
    display: public-affection;
    }

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,170
    Mentioned
    454 Post(s)
    Tagged
    8 Thread(s)
    If it's mainly a PHP question, certainly, but be aware thet there's now a dedicated WP Forum too.

  3. #3
    SitePoint Addict
    Join Date
    Jan 2008
    Location
    Shaw AFB
    Posts
    282
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just ask the question.
    ~ Nate L ~

  4. #4
    SitePoint Zealot candlebain's Avatar
    Join Date
    May 2009
    Location
    Phoenix, AZ
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    body {
    display: public-affection;
    }

  5. #5
    SitePoint Zealot candlebain's Avatar
    Join Date
    May 2009
    Location
    Phoenix, AZ
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is my get_posts() code that gets everything in the whole site.

    'category_name' => 'Rock', is how I tried to filter the files. It got no results. Leaving that out, I get all attachments sitewide. I've also tried 'rock' which is the slug. It fails to return results.

    Code PHP:
    <?php
    $args = array(
    'post_type' => 'attachment',
    'category_name' => 'Rock',
    'numberposts' => -1,
    'post_status' => null,
    'post_parent' => null
    );
    $attachments = get_posts($args);
    if ($attachments) {
     foreach ($attachments as $post) {
      setup_postdata($post);
      the_title();
      the_attachment_link($post->ID, false);
      the_excerpt();
     }
    }
    ?>

    I probably just need to start from scratch, but need guidance.
    body {
    display: public-affection;
    }

  6. #6
    Mazel tov! bronze trophy kohoutek's Avatar
    Join Date
    Aug 2004
    Location
    Hamburg, Germany
    Posts
    4,248
    Mentioned
    30 Post(s)
    Tagged
    0 Thread(s)
    Have you contemplated using custom fields for this? Seems like a more fitting approach to what you're trying to do.

    You can then retrieve the information by pulling all custom fields via
    Code PHP:
    <?php $custom_fields = get_post_custom(); ?>

    Or you could use a plugin such as this one: http://wordpress.org/extend/plugins/...-field-values/
    Maleika E. A. | Rockatee | Twitter | Dribbble



  7. #7
    SitePoint Zealot candlebain's Avatar
    Join Date
    May 2009
    Location
    Phoenix, AZ
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So I could use custom fields for the attachments?

    I assume I'd probably need to label the custom field for each class differently so I could pull the files in independent of each other?

    So, rock-1-files, rock-2-files, rock-3-files?
    body {
    display: public-affection;
    }

  8. #8
    Mazel tov! bronze trophy kohoutek's Avatar
    Join Date
    Aug 2004
    Location
    Hamburg, Germany
    Posts
    4,248
    Mentioned
    30 Post(s)
    Tagged
    0 Thread(s)
    I'd be more descriptive in naming your custom fields, so if I have a PDF, I'd name the custom field "pdf", the lecture would be named "lecture", and the word document would be named "document".
    Maleika E. A. | Rockatee | Twitter | Dribbble



  9. #9
    SitePoint Zealot candlebain's Avatar
    Join Date
    May 2009
    Location
    Phoenix, AZ
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Then how would I sort by class?
    body {
    display: public-affection;
    }

  10. #10
    SitePoint Addict
    Join Date
    Jan 2008
    Location
    Shaw AFB
    Posts
    282
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 blabla.com/class-1 and it instantly takes them to that category, with the posts relative to their class.
    ~ Nate L ~

  11. #11
    Mazel tov! bronze trophy kohoutek's Avatar
    Join Date
    Aug 2004
    Location
    Hamburg, Germany
    Posts
    4,248
    Mentioned
    30 Post(s)
    Tagged
    0 Thread(s)
    You'll need to read up on Custom Fields as it's important that you understand what this function does and how it works: http://codex.wordpress.org/Custom_Fields

    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.
    Maleika E. A. | Rockatee | Twitter | Dribbble



  12. #12
    SitePoint Zealot candlebain's Avatar
    Join Date
    May 2009
    Location
    Phoenix, AZ
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok. I think I understand. I'll experiment and then check back once I have something working.

    Thanks for your help.
    body {
    display: public-affection;
    }

  13. #13
    Mazel tov! bronze trophy kohoutek's Avatar
    Join Date
    Aug 2004
    Location
    Hamburg, Germany
    Posts
    4,248
    Mentioned
    30 Post(s)
    Tagged
    0 Thread(s)
    That's great! And when you get stuck, do come back and we'll get it sorted.
    Maleika E. A. | Rockatee | Twitter | Dribbble



  14. #14
    SitePoint Zealot candlebain's Avatar
    Join Date
    May 2009
    Location
    Phoenix, AZ
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok...so I'm getting stuck. I know how the custom fields work pretty well now, but I don't get how I can use documents/attachments with this. It just seems like text entry to me.

    How do you see this being used with the docs?
    body {
    display: public-affection;
    }

  15. #15
    SitePoint Zealot candlebain's Avatar
    Join Date
    May 2009
    Location
    Phoenix, AZ
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by NateL View Post
    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 blabla.com/class-1 and it instantly takes them to that category, with the posts relative to their class.
    This is what I was thinking originally. How would you then collect all the attachments from one category into a single page?
    body {
    display: public-affection;
    }

  16. #16
    SitePoint Addict
    Join Date
    Jan 2008
    Location
    Shaw AFB
    Posts
    282
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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)
    ~ Nate L ~

  17. #17
    SitePoint Zealot candlebain's Avatar
    Join Date
    May 2009
    Location
    Phoenix, AZ
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by NateL View Post
    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.
    body {
    display: public-affection;
    }

  18. #18
    Mazel tov! bronze trophy kohoutek's Avatar
    Join Date
    Aug 2004
    Location
    Hamburg, Germany
    Posts
    4,248
    Mentioned
    30 Post(s)
    Tagged
    0 Thread(s)
    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: http://codex.wordpress.org/Using_Ima...le_Attachments

    An easier route would be to look for a plugin that allows you to easily manage your media library and output results as needed: http://wordpress.org/extend/plugins/...+library&sort=

    Sorry, can't be of more help there. I've worked a lot with custom fields but not the media library.
    Maleika E. A. | Rockatee | Twitter | Dribbble



  19. #19
    SitePoint Zealot candlebain's Avatar
    Join Date
    May 2009
    Location
    Phoenix, AZ
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks anyways. I'm starting to feel like this isn't possible. I'm going to rethink my plans.
    body {
    display: public-affection;
    }

  20. #20
    SitePoint Addict
    Join Date
    Jan 2008
    Location
    Shaw AFB
    Posts
    282
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Instead of

    PHP Code:
    'post_parent' => null 
    Try
    PHP Code:
    '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.

    PHP Code:
    'category' => '1'
    ~ Nate L ~

  21. #21
    SitePoint Guru
    Join Date
    Oct 2008
    Location
    Melbourne
    Posts
    754
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

    PHP Code:
    function get_attachments_by_cat($cat) {
        
    // make a new Loop that pulls posts from the specified category
    query_posts('posts_per_page=-1&cat='.$cat);

    // 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->IDfalsefalsefalse);
               echo 
    '</h4>';
               echo 
    wp_get_attachment_link($attachment->ID'thumbnail'truetrue);
               echo 
    '</li>';
           }
          echo 
    '</ul>';
    }

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

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

    PHP Code:
    get_attachments_by_cat('88'); 
    (where 88 is the category number you want).

    Does that sort of help?

    It's a bit query-intensive :\
    Last edited by raena; Jun 7, 2010 at 03:46. Reason: uhhh typoz
    "I'm Commander Shepard, and this is
    my favourite post on the internet."

    We'll miss you, Dan Schulz.

  22. #22
    SitePoint Zealot candlebain's Avatar
    Join Date
    May 2009
    Location
    Phoenix, AZ
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! I'll give it a shot.
    body {
    display: public-affection;
    }

  23. #23
    SitePoint Zealot candlebain's Avatar
    Join Date
    May 2009
    Location
    Phoenix, AZ
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It works! You're awesome. Thanks so much.
    body {
    display: public-affection;
    }

  24. #24
    SitePoint Guru
    Join Date
    Oct 2008
    Location
    Melbourne
    Posts
    754
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, awse!

    Let us know if you're having any trouble with it.
    "I'm Commander Shepard, and this is
    my favourite post on the internet."

    We'll miss you, Dan Schulz.

  25. #25
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    candlebain & anybody else looking to do something similar, I suggest you check out the Magic Fields plugin: http://magicfields.org/. 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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •