• Resolved grungepuppy

    (@grungepuppy)


    this seemed simple at the time, but i’m having trouble figuring out how to execute it.

    this is what needs to happen.

    project page:
    – list of links to YEARLY archives from “projects” category. link to “2010”, link to “2009”, etc. meant to direct to all “projects” postes in their respective years.

    project > year:
    – all posts from “projects” category from specified year.

    it seems simple but for some reason i’m over thinking something or what. i guess the question is this…

    how do i generate a list that has the YEARS for all posts made to category “projects”?

    how do i make those into links to pages/archives that will show all posts made in those years in the “projects” category?

    i was thinking about making actual YEAR subcategories, but i would like to go off of the post’s year if i can.

    thanks for any help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • EDIT: Sorry, this gets ALL archives, not just Projects. I will see if I can provide another solution.

    See the wp_get_archives() function.

    You can add filters for the projects category. Add these functions to your functions.php:

    function mam_getarchives_join_filter ($join) {
       global $mam_global_getarchives_join;
       if ($mam_global_getarchives_join) {
          $join .= ' ' . $mam_global_getarchives_join;
       }
       return $join;
    }
    function mam_getarchives_where_filter ($where) {
       global $mam_global_getarchives_where;
       if ($mam_global_getarchives_where) {
          $where .= ' ' . $mam_global_getarchives_where;
       }
       return $where;
    }
    add_filter('getarchives_join','mam_getarchives_join_filter');
    add_filter('getarchives_where','mam_getarchives_where_filter');

    And use this code in your template:

    $mam_global_getarchives_join = "
       JOIN $wpdb->term_relationships tr ON ($wpdb->posts.ID = tr.object_id)
       JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
       JOIN $wpdb->terms t ON (tt.term_id = t.term_id)
       ";
    $mam_global_getarchives_where = " AND tt.taxonomy = 'category' AND t.name = 'projects'";
    wp_get_archives( array('type' => 'yearly'));
    Thread Starter grungepuppy

    (@grungepuppy)

    thanks for the response! i couldn’t quite get that to work how i wanted, but i have a new idea that seems a little easier.

    i’m just going to have url-defined year variables:

    site.com/projects/?project=2009

    <?php
    $yr = $_GET['project'];
    query_posts('cat=3&year='.$yr);
    ?>

    this way, i can just have the year specific content from projects load based on the variable i have the link. it works but i have a new question.

    is there a way i can execute (or i guess, NOT execute) the loop based on whether or not the variable $yr is defined? the idea would be that the loop would only show up if a specific year has been defined. else, the loop should not show up and the page should show no content. as it stands right now, all projects posts will show and only the defined ones will show (as they should) when the variable is defined.

    You can test for the presence of the project variable:

    <?php
    if (isset('$_GET['project'])) {
       $yr = $_GET['project'];
       query_posts('cat=3&year='.$yr);
       // rest of loop
    } else {
      // No project set
    )
    ?>
    Thread Starter grungepuppy

    (@grungepuppy)

    excellent! i scooted some things around and this is what worked:

    <?php
    
    $yr = $_GET['yr'];
    if ($yr != "")  {
    query_posts('cat=3&year='.$yr);
    
       // loop
    
     } else { 
    
        //no loop
    }
    ?>

    the loop works within this set up.
    i was even able to get the page content so show up in the ELSE area by using the rewind trick. so now, the page content will show up variable is blank (or wrong), and the specific posts will show up if the correct variable is defined.

    thanks for all your help!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Date AND Cat post…’ is closed to new replies.