• Hi all, I am new to WordPress and don’t really know how to code.

    Let say I have some posts and pages under category “media release”. Each post also has their own year of releasing tag e.g 2010, 2011, 1999, etc. I want to have a menu called “Media Release”, which when people click it, it brings to a page where all the post and pages under category “media release” listed based on the year tag.

    What is the best approach to this?

    Your help is most appreciated

    Thank you

Viewing 7 replies - 1 through 7 (of 7 total)
  • you could do something like that using tags for the years like you said.

    I just tested the following code, it should list all your date tags, you can specify a category by id in the array (cat => 4).

    2010
    2011
    2012

    each date tag will link to its respective tag archive.

    <ul> <h5>
    <?php	
    
    $args=array(
    
        'posts_per_page' => -1,
         cat => 4
    );
    $my_query = null;
      $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
        echo '';?>
     <?php  while ($my_query->have_posts()) : $my_query->the_post();
            $posttags = get_the_tags();
    		if ($posttags) {
    			foreach($posttags as $tag) {
    				$all_tags_arr[] = $tag->term_id; //USING JUST $tag MAKING $all_tags_arr A MULTI-DIMENSIONAL ARRAY, WHICH DOES WORK WITH array_unique
    			}
    		}endwhile;
    } ?>
    
    <?php
    wp_reset_query();  // Restore global post data stomped by the_post().
    
    $tags_arr = array_unique($all_tags_arr); //REMOVES DUPLICATES
    	//echo '<pre>'.print_r($tags_arr, true).'</pre>'; //OUTPUT FINAL TAGS FROM CATEGORY
    
    echo '<ul>';
    foreach ($tags_arr as $tag) {
    echo '<li><a href="' . get_tag_link($tag) . '">' . get_tag($tag)->name . '</a></li>';
    } ?>
    </ul>
    </h5>

    it’s just a matter of how you want to get it in the page. You can use it in your theme page template with a conditional statement or make a custom page template.

    Thread Starter manthono

    (@manthono)

    Hi deepbevel, thank you very much for your response.
    I have a question:
    Can I make the page list all item like the following hierarchy?

    Title: Media Release Archive

    Year 2010
    – item 1
    – item 2
    – item 3

    Year 2011
    – item 1
    – item 2
    – item 3

    Year 2012
    – item 1
    – item 2
    – item 3

    I am aware that I would have to make a custom page for ‘media release” category. But I don’t know how to display it above way.

    thank you very much

    yes, but my method would perhaps be not as good as it should. It would require a new query for each tag category.
    the reason is, it can only pull posts which have a common tag, so no way to make it get all your date tags, only one per query.

    <?php
    //gets most recent post tag in specified category, then lists all posts with that tag if in specified category.
        global $post;
        query_posts ('cat=4 &posts_per_page=1'); ?>
      <?php if ( have_posts() ) : ?>
     <?php while (have_posts()) : the_post(); ?>
    <h4>
    <?php the_tags( __( ' ',
    ' ' ), ', ', '<br />'); ?> </p><?php
    $posttags = get_the_tags($post->ID);?>
    </h4>
    <ul>
    <?php $tags = wp_get_post_tags($post->ID);
    if ($tags) {
      echo ''; $first_tag = $tags[0]->term_id;
      $args=array(
        'tag__in' => array($first_tag),
        'showposts'=>-0,
        'caller_get_posts'=>1,
        'order'    => 'ASC' );?>
    <?php
      $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
       while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <p style="padding: 1px; margin: 0;">
    <a href="<?php the_permalink() ?>">
    <?php the_title(); ?> </a></p>
          <?php endwhile;}}?>
        <?php endwhile; ?>
        <?php else : ?>
        <!-- html code if nothing found -->
        <?php endif; ?>
        <?php wp_reset_query();?>
    </ul>

    so you’d need this entireblock of code for each category ??

    If I were not so busy I’d try and merge the two, so each tag in a category also lists all posts in yhat category with that tag. It would requie some time, I’m not exactly great with php.

    just to check.. I’m assuming you are reserving your categores, and using tags for dates, for a reason?

    otherwise, why not just make the dates as the categories?
    like this

    Thread Starter manthono

    (@manthono)

    Thank you very much for your help. I really appreciate it.

    I was just thinking it might be the most reasonable way to organize posts. i had no idea that using tag could be more complicated when displaying it.

    My intention was like this:

    Title: Media Release Archive [this is category]

    Year 2010 [this is tag]
    – item 1
    – item 2
    – item 3

    Year 2011 [this is tag]
    – item 1
    – item 2
    – item 3

    Year 2012 [this is tag]
    – item 1
    – item 2
    – item 3

    I am no good in php. your block of code will takes me days to understand :-p

    I will try to read the link you give too.

    Regards

    okay then, I see you want categories as a spaerate taxonomy from the date tag. So my link won;t help.

    However you can also make categories with parent-child relationships.

    Parent Category: Media: Release Archive
    Child Category: Year 2112
    – item 1
    – item 2
    – item 3

    You’ll notice you can do that when you create a category, theres’ a drop down selector for it on the category edit page.

    However, just like our tags within categories, your lists will not automatically display the relationship. But it can be done with code or plugins. Or even a custom menu instead of pages.

    Then, there’s also custom taxonomies, or even custom post types..

    Welcome to the world of content managment, it’s endless!

    Let me know how it goes, it just occured to me I can write the above tags-in-categories code so it will get a different category with a conditional statement,
    Like:
    “if is page Media Release Archive 2012,
    query_posts (‘cat=3 &posts_per_page=1’); ?>

    “if is page Media Release Archive 2011,
    query_posts (‘cat=2 &posts_per_page=1’); ?>

    “if is page Media Release Archive 2010,
    query_posts (‘cat=1 &posts_per_page=1’); ?>

    then, the rest of the code would follow, so much less code!

    this could work for you, so let me know..

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘how to create a special page’ is closed to new replies.