show post by category related to archive post date – how to ?
-
Hi everybody,
I’m having a really bad time to make this work ..
I have a archive template, which works fine (build by custom-post-type, call archive),
the archive section works perfectly, and dsiplay my post in the permalink good,
as: mydomain.com/archive
mydomain.com/archive/2013
mydomain.com/archive/2013/01etc
However,
Once I acced ot the single post from this csutom-post, by the archive, the permalink get like:
mydomain.com/archive/post_name
I’ve manage via a plugin to make ti work as i wanted , such as
mydomain.com/archive/2013/01/post_name
This is not working properly in the breadcrumb, it jsut display: Home -> postname, id like to have the main slug as the permalink.
My main problem im having, is that those custom_type single file ( so the post, have a sidebar, which display, most viewed post, post by x and y category, etc.
It only show the current post, and not the post related to the date I’ve access from the archive . . .
To make it more clear, let say i’m in the archive page 2013, I access to the post A from the archive page 2013;
In this post at the moment, It just shows me this same post, It should show me the the most viewed post from the year 2013, the post from the category 2013,etc
If I access from 2013/01, it should display in the sidebar the post related to the date 2013/01 . ..
this is code I use to display those post . . .
<h3><a href="">More from this edition</a></h3> <?php global $query_string; query_posts( $query_string . '&posts_per_page=5' ); while(have_posts()): the_post(); ?> <ul class="middle_new"> <li> <a href="<?php the_permalink() ?>" class="main-headline"><div class="tabber-image"><?php the_post_thumbnail('small-thumb'); ?></div><div class="archives_info"><?php the_title(); ?></a> <p><?php echo excerpt(9); ?> <ul class="headlines2-info"> <li><?php the_time('F jS, Y'); ?></li> </ul> </div></div></p> <div class="headlines-info"> </div><!--headlines-info--> </li> </ul> <?php endwhile; wp_reset_query(); ?> </ul>
I also tried instead:
<ul class="archive2"> <?php global $wp_query; $args = array_merge( $wp_query->query_vars, array('posts_per_page' => 4 ) ); /*, 'tag' => featured*/ query_posts( $args ); $i=0; while(have_posts()): the_post(); ?> <?php if (!in_category('8')) continue; ?> <li> <div class="archive2-image"> <?php if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) { ?> <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail('small-thumb'); ?></a> <?php } ?> </div><!--archive2-image--> <div class="archive2-text"> <a href="<?php the_permalink() ?>" class="main-headline2"><?php the_title(); ?></a> <p><?php echo excerpt(18); ?></p> <div class="headlines-info"> <ul class="headlines2-info"> <li><?php the_time('F jS, Y'); ?></li> </ul> </div><!--headlines-info--> </div><!--archive-text--> </li> <?php $i++; if($i >= 4) break; endwhile; wp_reset_query(); ?> </ul> </div>
But doesn’t work . . .
here is my functiosn which i use to create the custom_post_type, and rewrite the permalink, in case it helps . . .
add_action('init', 'demo_register_post_type'); function demo_register_post_type() { register_post_type('archive', array( 'labels' => array( 'name' => 'Archives', 'singular_name' => 'Archive', 'add_new' => 'Add new archive', 'edit_item' => 'Edit archive', 'new_item' => 'New archive', 'view_item' => 'View archive', 'search_items' => 'Search archive', 'not_found' => 'No archive found', 'not_found_in_trash' => 'No archive found in Trash' ), 'public' => true, 'has_archive' => true, 'hierarchical' => true, 'supports' => array( 'title', 'excerpt', 'thumbnail', 'editor' ), 'taxonomies' => array('category', 'post_tag') // this is IMPORTANT )); } add_action('init', 'demo_add_default_boxes'); function demo_add_default_boxes() { register_taxonomy_for_object_type('category', 'archive'); register_taxonomy_for_object_type('post_tag', 'archive'); } add_action('generate_rewrite_rules', 'my_datearchives_rewrite_rules'); function my_datearchives_rewrite_rules($wp_rewrite) { $rules = my_generate_date_archives('archive', $wp_rewrite); $wp_rewrite->rules = $rules + $wp_rewrite->rules; return $wp_rewrite; } function my_generate_date_archives($cpt, $wp_rewrite) { $rules = array(); $post_type = get_post_type_object($cpt); $slug_archive = $post_type->has_archive; if ($slug_archive === false) return $rules; if ($slug_archive === true) { $slug_archive = $post_type->name; } $dates = array( array( 'rule' => "([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})", 'vars' => array('year', 'monthnum', 'day')), array( 'rule' => "([0-9]{4})/([0-9]{1,2})", 'vars' => array('year', 'monthnum')), array( 'rule' => "([0-9]{4})", 'vars' => array('year')) ); foreach ($dates as $data) { $query = 'index.php?post_type='.$cpt; $rule = $slug_archive.'/'.$data['rule']; $i = 1; foreach ($data['vars'] as $var) { $query.= '&'.$var.'='.$wp_rewrite->preg_index($i); $i++; } $rules[$rule."/?$"] = $query; $rules[$rule."/feed/(feed|rdf|rss|rss2|atom)/?$"] = $query."&feed=".$wp_rewrite->preg_index($i); $rules[$rule."/(feed|rdf|rss|rss2|atom)/?$"] = $query."&feed=".$wp_rewrite->preg_index($i); $rules[$rule."/page/([0-9]{1,})/?$"] = $query."&paged=".$wp_rewrite->preg_index($i); } return $rules; }
ANy help would be amazing, this si really urgent,
thank you
- The topic ‘show post by category related to archive post date – how to ?’ is closed to new replies.