• Resolved David Gard

    (@duck_boy)


    Hey all,

    I am trying to create an archive for a site, and I have the Archive template (archives.php) up and running fine, displaying the posts by month – trouble is, when I click the link I am taken to my index page with no results.

    An example of the link generated is –

    https://www.mydomain.com/clientbalances/2010/10/

    Index is very simple, as below, and I thought this would do the trick, but should I be adding some other code somewhere?

    Any pointers would be appriciated.

    Thanks.

    <div class="section-title"><h2>Your selected Client Balances</h2></div>
    <?php
    if(have_posts()) :
    	while(have_posts()) : the_post();
    ?>
    		<li>
    			<p class="news_title_padd" id="post-<?php the_ID(); ?>">
    				<a href="<? the_guid() ?>" rel="bookmark" title="<? the_title_attribute(); ?>"><? echo the_title(); ?></a>
    				- <strong><? the_time('jS F Y'); ?></strong>
    			</p>
    		</li>
    <?php
    	endwhile;
    endif;
    ?>
Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter David Gard

    (@duck_boy)

    Any pointers here at all? One correction – It’s the 404 page I am taken to when I click on one of the Archives.

    Thanks.

    Hi, you may want to use the_permalink() instead of the_guid()

    just checking for typo…. is it archives.php or archive.php?

    archive.php is correct in the heirarchy (no s)

    does your server have an issue with the php short tags?

    <? vs <?php

    Hi, you may want to use the_permalink() instead of the_guid()

    ah yeah, has the permalink for the post changed at all? I believe the GUID is generated as a unique identifier on the post. The permalink can change, the guid doesn not….. AFAIK (Not done much delving into this)

    Thread Starter David Gard

    (@duck_boy)

    Hey guys, thanks for the replies.

    Regarding the use of the_guid(), I need this as it is actually files that are listed as opposed to posts. This does work, it’s just that ‘https://www.mydomain.com/clientbalances/2010/10/&#8217; is saying that the page is not found.

    When I changed ‘archives.php’ to ‘archive.php’ all I get is one link ‘?Archives – 3rd December 2010’ that points back to the archives page.

    Oh, no short tags are no issue, server is set to allow them.

    Here is my archive.php file –

    <?php
    /**
     * @package WordPress
     * @subpackage DD Intranet
     * @theme Client Balances
     */
    /*
    Template Name: Archives
    */
    
    add_filter('getarchives_where', 'getarchives_filter', 10, 2);
    function getarchives_filter($where, $args){
    	$where = "WHERE post_type = 'attachment' AND post_status = 'inherit'";
    	return $where;
    }
    get_header();
    ?>
    <div id="pageContainer">
    	<div id="leftContainer">
    		<div class="inside">
    			<div class="section-title"><h2>Historic Client Balances</h2></div>
    			<ul class="attachments">
    				<?php wp_get_archives('type=daily&format=custom&before=<li class="arrow">&after=</li>'); ?>
    			</ul>
    		</div>
    	</div>
    	<div id="rightContainer">
    		<?php get_sidebar(); ?>
    	</div>
    </div>
    <div class="clear"></div>
    <?php get_footer(); ?>

    Thanks.

    Thread Starter David Gard

    (@duck_boy)

    Ah, I think I may have found the problem – On the ‘archives.php’ page I use a filter to change the $where variable for the query –

    add_filter('getarchives_where', 'getarchives_filter', 10, 2);
    function getarchives_filter($where, $args){
    	$where = "WHERE post_type = 'attachment' AND post_status = 'inherit'";
    	return $where;
    }

    But I’ve just printed out the $wp_query for index when a link from the arcive is clicked and it come out as below –

    SELECT SQL_CALC_FOUND_ROWS wp_2_posts.* FROM wp_2_posts WHERE 1=1 AND YEAR(wp_2_posts.post_date)='2010' AND MONTH(wp_2_posts.post_date)='12' AND wp_2_posts.post_type = 'post' AND (wp_2_posts.post_status = 'publish' OR wp_2_posts.post_status = 'private') ORDER BY wp_2_posts.post_date DESC LIMIT 0, 5

    I need to somehow change this –

    wp_2_posts.post_type = 'post' AND (wp_2_posts.post_status = 'publish' OR wp_2_posts.post_status = 'private')

    to this –

    wp_2_posts.post_type = 'attachment' AND wp_2_posts.post_status = 'inherit'

    Do you know of a filter to do that, as a quick glance in the ‘query.php’ file didn’t yeild an obvious one?

    Thanks.

    Thread Starter David Gard

    (@duck_boy)

    Sorted –

    add_filter('posts_where', 'posts_filter', 10, 2);
    function posts_filter($where = '', $dates){
    	global $wp_query;
    	$year = $wp_query->query_vars['year'];
    	$month = $wp_query->query_vars['monthnum'];
    	$where = "AND YEAR(wp_2_posts.post_date)='$year' AND MONTH(wp_2_posts.post_date)='$month' AND post_type = 'attachment' AND post_status = 'inherit'";
    	return $where;
    }
    query_posts($query_string);

    Thanks for your help guys.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Archive not showing any posts’ is closed to new replies.