简体   繁体   中英

Load content into div based on month

I am needing to load content for the specific month defined by the user. If the user picks the month of July, a list of events (the content in the this case) is shown for the month of July. If the user picks June, all of the June events are shown. Right now, I have a script set up to where the user clicks a "next" link to switch months. Only month is shown at a time. When the user clicks the "next" link, I would like for all of the next months content to load. For example, if the user is on the month of June and they click next than July will will show up as well as all of the July events. To load the new events I am using:

window.location = "/<?php echo $site_slug; ?>/ministries/events/<?php echo $_GET['year']; ?>/<?php echo $_GET['month']; ?>;

This is called when the user clicks the "next" button. The $_GET['year'] and $_GET['month'} variables are being populated by an API. When I click the next button, I am not getting the "year" and "month" values but just a hashtag. My question is, is the javascript syntax correct?

EDIT: Added more code:

Jquery:

    <script type="text/javascript">
        $('document').ready(function(){
            $(".event_months li:nth-child(3)").addClass("doShow");

            $("a.next").click(function() {
                $('.first').toggleClass("first");
                var $toHighlight = $('.doShow').next().length > 0 ? $('.doShow').next() : $('.event_months li').first();
                $('.doShow').removeClass('doShow');
                $toHighlight.addClass('doShow');
                window.location = "/<?php echo $site_slug; ?>/ministries/events/<?php echo $_GET['year']; ?>/<?php echo $_GET['month']; ?>;

            });

          });
     </script>

Not sure if the API call will help but here it is:

<?php getContent(
    "event",
    "display:list", 
    "order:recent",
    "find_group:".$site_slug,
    "groupby:month",
    "year:".$_GET['year'], 
    "month:".$_GET['month'],
    "group_show:<li class='noShow'>__slug__</li>"
    ); 
?> 

I setup your code like you did (I had to guess at the "next" link), and couldn't get it to work. The problem, from what I can tell, is that you're using $_GET to get the year and month variables from the URL. Use $_REQUEST , instead:

<a class="next" href="/?year=2012&month=06" onclick="return false;">Next</a>

You'll also need the "return false" to stop the link from following, IF you want to use your window.location line.

Don't forget (like you've mentioned) to make sure your window.location has a closing parenthesis.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM