WordPress.org

Ready to get started?Download WordPress

Forums

Smart Archives Reloaded
[resolved] Smart-archives directly show all the posts from the month (6 posts)

  1. mmya
    Member
    Posted 3 years ago #

    Hello, I am using the smart-archives plugin and I need that when the user click on a month all the posts from that month would be directly displayed (not a list with the titles, but the complete posts). I have seen in another tag, titled:
    [Plugin: Smart Archives Reloaded] Remove the link to the monthly archive in fancy archive
    it is this issue commented. I have copied that code:

    / The "fancy" archive
    	protected function generate_fancy() {
    		$months_long = $this->get_months();
    
    		$year_list = html("ul class='tabs year-list'",
    			$this->generate_year_list()
    		, "\n");
    
    		$block = '';
    		foreach ( $this->yearsWithPosts as $year ) {
    			// Generate top panes
    			$months = html("ul id='month-list-$year' class='tabs month-list'",
    				$this->generate_month_list($year)
    			, "\n\t");
    
    			// Generate post lists
    			$list = '';
    			for ( $i = 1; $i <= 12; $i++ ) {
    				if ( ! $current = @$this->monthsWithPosts[$year][$i] )
    					continue;
    
    				// Append to list
    				$list .= html('div class="pane"',
    					"\n\t\t" . html('h2 class="month-heading"',
    						"$months_long[$i] $year "
    						.html('span class="month-archive-link"',
    							'('. html_link($current['link'], __('View complete archive page', 'smart-archives-reloaded')) .')'
    						)
    					)
    					.html('ul class="archive-list"',
    						$this->generate_post_list($current['posts'], "\n\t\t\t")
    					, "\n\t\t")
    				, "\n\t");
    			} // end month block
    
    			$block .= html('div class="pane"', $months . $list, "\n");
    		} // end year block
    
    		// Wrap it up
    		return html('div id="smart-archives-fancy"', $year_list . $block);
    	}

    but it does not work, I think that it is because I have to modify this code too:

    //_____HELPER TEMPLATES_____
    
    	protected function generate_year_list( $current_year = 0 ) {
    		$year_list = '';
    		foreach ( $this->get_years_with_posts( 'asc' ) as $year ) {
    			$year_list .=
    			html( 'li',
    				$this->a_link( get_year_link( $year ), $year, $year == $current_year )
    			);
    		}
    
    		return $year_list;
    	}
    
    	protected function generate_month_list( $year, $current_month = 0, $inline = false ) {
    		$month_names = $this->get_months( $this->args->month_format );
    
    		$in_current_year = ( get_query_var( 'year' ) == $year );
    
    		$month_list = '';
    		foreach ( range( 1, 12 ) as $i ) {
    			$month = $month_names[$i];
    
    			if ( in_array( $i, $this->get_months_with_posts( $year ) ) ) {
    				$url = $this->args->anchors ? "#{$year}{$i}" : get_month_link( $year, $i );
    				$tmp = $this->a_link( $url, $month, $in_current_year && $i == $current_month );
    			}
    			else {
    				$tmp = html( 'span class="empty-month"', $month );
    			}
    
    			if ( $inline )
    				$month_list .= " $tmp";
    			else
    				$month_list .= "\n\t\t" . html( 'li', $tmp );
    		}
    
    		return $month_list;
    	}
    
    	protected function generate_post_list( $year, $i, $indent ) {
    		$posts = $this->get_posts( $year, $i );
    
    		if ( empty( $posts ) )
    			return false;
    
    		$post_list = '';
    		foreach ( $posts as $post ) {
    			$list_item = $this->args->list_format;
    
    			foreach ( SAR_Core::get_available_tags() as $tag )
    				if ( false !== strpos( $this->args->list_format, $tag ) )
    					$list_item = str_replace( $tag, call_user_func( array( $this, 'substitute_' . substr( $tag, 1, -1 ) ), $post ), $list_item );
    
    			$post_list .= $indent . html( 'li', $list_item );
    		}
    
    		return $post_list;
    	}
    
    	protected function get_months( $format = 'long' ) {
    		global $wp_locale;
    
    		$months = array();
    		foreach ( range( 1, 12 ) as $i ) {
    			if ( 'numeric' == $format ) {
    				$months[$i] = zeroise( $i, 2 );
    				continue;
    			}
    
    			$month = $wp_locale->get_month( $i );
    
    			if ( 'short' == $format )
    				$month = $wp_locale->get_month_abbrev( $month );
    
    			$months[$i] = esc_html( $month );
    		}
    
    		return $months;
    	}
    
    	protected function a_link( $link, $title, $current ) {
    		$el = $current ? 'a class="current"' : 'a';
    
    		return html( $el . ' href="' . $link . '"', $title );
    	}

    I do not know too much php code, so I be someone to help me.

    Many thanks

  2. mmya
    Member
    Posted 3 years ago #

    I will explain it better. I have this page made with wordpress and smart-archives plugin and I want that when you click on a month the complete archives from the month would be displayed in the pane down, instead of links to each archive. You can eee that the archives will be sort links to news and it would be better that all the archives from the month would be completely displayed down in order that the navigation to get the news links would not be too long.

    Any help would be really appreciate, because I have been trying to do this for two days. Probably it would be really simple, but I don't get to do it. Pleae tell me the code I should modify.

    Many thanks in advance :-)

  3. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    You don't need to modify the plugin at all. Just use the 'menu' format:

    <?php smart_archives('format=menu'); ?>

    You will need to place that code in your theme's archive.php file as well.

  4. mmya
    Member
    Posted 3 years ago #

    Many thanks, Scribu,

    I've been trying to get this for a lot of time and now it works. And it was really simple. Thanks again.

    One more question, please. I don't know why, when I get into the page that shows the smart-archives in th 'menu' format it doesn't get into the last year and month. I think it should do it, but it doen't works correctly. When I use the fancy archives it get into the current year and month, but it doesn't work when I use the menu format. ┬┐Can you help me with this issue?

    I would be really grateful.
    Thanks again.

  5. mmya
    Member
    Posted 3 years ago #

    I have solvent it by redirecting the medios page (although I suppose it is not the better way to do it). But now I have another question and it is that the archive just shows 10 entries. In january 2011 there is 12, but just 10 are shown. Do you know what is the problem?

    Many thanks again.

  6. mmya
    Member
    Posted 3 years ago #

    Hello, I have found the limit of 10 posts in the WordPress preferences, and I have removed it. Thanks for all.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic