• Resolved Nith

    (@nith)


    Hello,

    I looking for help to implement some functionality, but don’t have the WordPress dev knowledge to pull it off. The details are below:

    1. Have a drop down menu which contains months where there are posts available, sort of like an archive thing. (How would I populate this?!)
    2. When the user selects a month from the drop-down, this month with be used as a parameter in the url. I.E https://www.mydomain.com/pages/folio/?filter=September
    3. (This step I can do myself).

    4. Then, if the filter parameter is set, I want the code below (which i currently have fetching my posts) to be modified to only fetch posts from that month (which will be the value of the $_GET[‘filter’]

    Code I currently have fetching posts:

    <?php
    	$taxonomy = 'category';
    	$param_type = 'category__in';
    	$term_args=array(
    		'include'=> '3',
    		'orderby' => 'name',
    		'order' => 'ASC'
    	);
    	$terms = get_terms($taxonomy,$term_args);
    	if ($terms) {
    		foreach( $terms as $term ) {
    			$args=array(
    				"$param_type" => array($term->term_id),
    				'post_type' => 'post',
    				'post_status' => 'publish',
    				'posts_per_page' => 10,
    				'caller_get_posts'=> 1
    			); 
    
    			$my_query = null;
    			$my_query = new WP_Query($args);
    			if( $my_query->have_posts() ) {
    				$count = 0; ?>
    
    				<li>
    
    					<?php while ($my_query->have_posts()) : $my_query->the_post();
    					if ( ++$count > 1 && ($count - 1) % 2 == 0 ) echo '</li><li>' ; ?>
    
    						<!-- Removed irelevant code -->
    
    					<?php endwhile; ?>
    
    				</li>
    
    			<?php }
    		}
    	}
    
    	wp_reset_query();
    
    ?>

    Hopefully this isn’t too ambitious, I’ve tried to include as much detail as possible.

    Thanks in advance.

Viewing 1 replies (of 1 total)
  • There’s a built-in widget that does this already, under Admin > Themes > Wigets, titled Archives.

    Select the dropdown option, give the widget a title, job done, a dropdown that changes the page and selects posts based on the selected month.

    Or i’m sure it would work in conjunction with custom code if you had something broader in mind, but take a look at the widget first, it should save having to write something to do the same from scratch… ??

Viewing 1 replies (of 1 total)
  • The topic ‘Advanced Functionality’ is closed to new replies.