• 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/01

    etc

    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

Viewing 8 replies - 1 through 8 (of 8 total)
  • Try doing this:

    <?php
    $post_date = get_the_date('Y-m-d');//Put this inside post loop
    
    $start_date = date("Y-m-01", strtotime( $post_date ));//start of month of post date current post
    $end_date = date("Y-m-t", strtotime( $post_date ));//end of month of post date current post
    global $wpdb;
    global $post;
    $querystr = "
    SELECT wposts.*
    FROM $wpdb->posts wposts
        LEFT JOIN $wpdb->postmeta wpostmeta ON wposts.ID = wpostmeta.post_id
        LEFT JOIN $wpdb->term_relationships ON (wposts.ID = $wpdb->term_relationships.object_id)
        LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    WHERE wposts.post_date BETWEEN '$start_date' AND '$end_date'
    LIMIT 10
    ";
    $eventPosts = $wpdb->get_results($querystr, OBJECT);
    ?>
    <?php if(!empty($eventPosts)): ?>
    <?php global $post;?>
    <ul>
    <?php foreach($eventPosts as $post): setup_postdata($post); ?>
        <li><?php the_title(); ?></li>
    <?php endforeach; ?>
    </ul>
    <?php endif; wp_reset_query(); ?>

    I hope this helps.

    Cheers ??

    Thread Starter tibewww

    (@tibewww)

    hmmm,

    I tried

    <div id="sidebar_archive">
    <div class="side">
    
    		<div class="sidebar-widget">
    
    		<h3><a href="">More from this edition</a></h3>
    
    <?php
    $post_date = get_the_date('Y-m-d');//Put this inside post loop
    
    $start_date = date("Y-m-01", strtotime( $post_date ));//start of month of post date current post
    $end_date = date("Y-m-t", strtotime( $post_date ));//end of month of post date current post
    global $wpdb;
    global $post;
    $querystr = "
    SELECT wposts.*
    FROM $wpdb->posts wposts
        LEFT JOIN $wpdb->postmeta wpostmeta ON wposts.ID = wpostmeta.post_id
        LEFT JOIN $wpdb->term_relationships ON (wposts.ID = $wpdb->term_relationships.object_id)
        LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    WHERE wposts.post_date BETWEEN '$start_date' AND '$end_date'
    LIMIT 10
    ";
    $eventPosts = $wpdb->get_results($querystr, OBJECT);
    ?>
    <?php if(!empty($eventPosts)): ?>
    <?php global $post;?>
    <ul>
    <?php foreach($eventPosts as $post): setup_postdata($post); ?>
        <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>
    <?php endforeach; ?>
    </ul>
    <?php endif; wp_reset_query(); ?>
    
    		</ul>
    
    		<div class="widget-content">
    
    </div>

    It doesnt really work ?? :(,

    Thread Starter tibewww

    (@tibewww)

    its almost working, but its showing post from the original post of wordpress also :S

    I just need to display from the custom_type ‘archive’,
    and also to be able to show by week, ( such as: https://www.mydomain.com/archive/2013?w=52/post_title

    do you know how to achieve this by any chance ?? you re a saving life for me !

    The last code im using following your great help:

    <div class="sidebar-widget">
    
    		<h3><a href="">More from this edition</a></h3>
    
    <?php
    $post_date = get_the_date('Y-m-d');
    $start_date = date("Y-m-01", strtotime( $post_date ));//start of month of post date current post
    $end_date = date("Y-m-t", strtotime( $post_date ));//end of month of post date current post
    global $wpdb;
    global $post;
    $querystr = "
    SELECT wposts.*
    FROM $wpdb->posts wposts
        LEFT JOIN $wpdb->postmeta wpostmeta ON wposts.ID = wpostmeta.post_id
        LEFT JOIN $wpdb->term_relationships ON (wposts.ID = $wpdb->term_relationships.object_id)
        LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    WHERE wposts.post_date BETWEEN '$start_date' AND '$end_date'
    LIMIT 10
    ";
    $eventPosts = $wpdb->get_results($querystr, OBJECT);
    ?>
    <?php if(!empty($eventPosts)): ?>
    <?php global $post;?>
    <ul>
    <?php foreach($eventPosts as $post): setup_postdata($post); ?>
        <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></li>
    <?php endforeach; ?>
    </ul>
    <?php endif; wp_reset_query(); ?>
    		</ul>
    
    		<div class="widget-content">
    
    </div>
    Thread Starter tibewww

    (@tibewww)

    ok, After adding the Query to,

    SELECT wposts.*
    FROM $wpdb->posts wposts
        LEFT JOIN $wpdb->postmeta wpostmeta ON wposts.ID = wpostmeta.post_id
        LEFT JOIN $wpdb->term_relationships ON (wposts.ID = $wpdb->term_relationships.object_id)
        LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    WHERE wposts.post_date BETWEEN '$start_date' AND '$end_date'
    AND wposts.post_type = 'archive'

    it display the post only from the custom_post_type,

    But it keep repeating to display the same psot all the time ??

    This may help:
    $post_id = get_the_ID();
    — Don’t forget to put above line inside post loop and get_the_date() line as well

    SELECT wposts.*
    FROM $wpdb->posts wposts
        LEFT JOIN $wpdb->postmeta wpostmeta ON wposts.ID = wpostmeta.post_id
        LEFT JOIN $wpdb->term_relationships ON (wposts.ID = $wpdb->term_relationships.object_id)
        LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    WHERE wposts.post_date BETWEEN '$start_date' AND '$end_date'
    AND wposts.post_type = 'archive' AND wposts.post_ID !='$post_id'
    Thread Starter tibewww

    (@tibewww)

    Thank you so much gonna try in 30 min when i get back to the office, I need to display only post from a specific ID, I tried the query from wordpress codex, but didn’t work … do you have an idea about it?

    Thread Starter tibewww

    (@tibewww)

    Hi,

    I’ve been trying and doesn’t work . ..

    I’ve manage to display the post by:

    <?php
    $post_date = get_the_date('Y-m-d');
    $start_date = date("Y-m-01", strtotime( $post_date ));//start of month of post date current post
    $end_date = date("Y-m-t", strtotime( $post_date ));//end of month of post date current post
    global $wpdb;
    global $post;
    $querystr = "
    SELECT wposts.*
    FROM $wpdb->posts wposts
    WHERE wposts.post_date BETWEEN '$start_date' AND '$end_date'
    AND wposts.post_type = 'archive'
    
    LIMIT 5
    ";
    $eventPosts = $wpdb->get_results($querystr, OBJECT);
    ?>

    the ‘LEFT JOIN ‘ doesn’t make it work . ..

    However, I also need to display only a specific category, so I tried the two different following:

    <?php
    $post_date = get_the_date('Y-m-d');
    $start_date = date("Y-m-01", strtotime( $post_date ));//start of month of post date current post
    $end_date = date("Y-m-t", strtotime( $post_date ));//end of month of post date current post
    global $wpdb;
    global $post;
    $querystr = "
    SELECT wposts.*
    FROM $wpdb->posts wposts
    WHERE wposts.post_date BETWEEN '$start_date' AND '$end_date'
    AND wposts.post_type = 'archive'
    AND $wpdb->post2cat.category_id IN (27)
    
    LIMIT 5
    ";
    $eventPosts = $wpdb->get_results($querystr, OBJECT);
    ?>

    and also:

    <?php
    $post_date = get_the_date('Y-m-d');
    $start_date = date("Y-m-01", strtotime( $post_date ));//start of month of post date current post
    $end_date = date("Y-m-t", strtotime( $post_date ));//end of month of post date current post
    global $wpdb;
    global $post;
    $querystr = "
    SELECT wposts.*
    FROM $wpdb->posts wposts
    LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id)
    WHERE wposts.post_date BETWEEN '$start_date' AND '$end_date'
    AND wposts.post_type = 'archive'
    AND $wpdb->post2cat.category_id IN (27)
    
    LIMIT 5
    ";
    $eventPosts = $wpdb->get_results($querystr, OBJECT);
    ?>

    But it doesn’t display anything . . .

    about the $post_id = get_the_ID();

    Where should I put exactly ? my back end skills are really low . .. and to setup the date do you mean in this line $post_date = get_the_date(‘Y-m-d’);

    like $post_date = get_the_date('2013-12-25');

    Really appreciate all your help . .

    Thread Starter tibewww

    (@tibewww)

    Good news, i ve manage to solve the category feature by using:

    <div class="sidebar-widget">
    
    	<h3><a href="">Must read entertainement</a></h3>
    
    <?php
    $post_date = get_the_date('Y-m-d');
    $start_date = date("Y-m-01", strtotime( $post_date ));//start of month of post date current post
    $end_date = date("Y-m-t", strtotime( $post_date ));//end of month of post date current post
    global $wpdb;
    global $post;
    $querystr = "
    SELECT wposts.*
    FROM $wpdb->posts wposts
    LEFT JOIN $wpdb->term_relationships ON (ID = $wpdb->term_relationships.object_id)
    LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)WHERE wposts.post_date BETWEEN '$start_date' AND '$end_date'
    AND wposts.post_type = 'archive'
        AND $wpdb->term_taxonomy.term_id IN(27)
        AND $wpdb->term_taxonomy.term_id NOT IN(1000)
    
    LIMIT 5
    ";
    $eventPosts = $wpdb->get_results($querystr, OBJECT);
    ?>
    <?php if(!empty($eventPosts)): ?>
    <?php global $post;?>
    
    <ul>
    <?php foreach($eventPosts as $post): setup_postdata($post); ?>
        <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><?php echo excerpt(9); ?>
    						<ul class="headlines2-info">
    							<li><?php the_time('F jS, Y'); ?></li>
    						</ul></li>
    <?php endforeach; ?>
    </ul>
    <?php endif; wp_reset_query(); ?>
    		</ul>
    
    		<div class="widget-content">
    
    </div>

    The only problem left I have is that it just display from the matching month,

    If i acted by e.g., 2013?w=52

    ( by the week of a specific month from a specific year), id like the post to be display from this sequence of time . . .

    Otherwise if i acted by: 2013/12

    just from that month of that year,

    and If i acted by 2013

    Just from that year . ..

    If you have any idea .. would be wonderful . .. I didn’t really understand how to set up the get_the_date() . . .

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘show post by category related to archive post date – how to ?’ is closed to new replies.