Support » Plugins » Dynamic Date in query_posts

  • Ian Stewart


    Theme Wrangler

    Here’s my problem: I’m creating an issue-based magazine template. 3-5 times a year a set of 10-15 posts will be published under a particular issue theme with an editorial as a forward for it all. When I’m viewing an archived post from a particular issue I would like to have it’s issue-theme displayed before the post.

    Here’s my solution: My home page is a static page with dynamic elements (I want to reserve index.php for a blog about the magazine). It has these three loops:

    <div id="issue-theme">				
    	<h3>Issue Theme</h3>
    	<!-- begin latest issue theme -->
    	<?php query_posts('showposts=1&cat=4'); ?> <!-- cat-4 is my "theme" category -->
    	<?php while (have_posts()) : the_post(); ?>
    	<!-- do stuff -->
    	<?php endwhile; ?><!-- end latest issue theme -->
    <div id="editorial">
    	<!-- begin latest editorial -->
    	<?php query_posts('showposts=1&cat=3'); ?> <!-- cat-3 is my "editorial" category -->
    	<?php while (have_posts()) : the_post(); ?>
    	<!-- do stuff -->
    	<?php endwhile; ?><!-- end latest editorial -->
    </div><!-- #editorial -->
    <div id="issue-index">
    	<h3>In this issue</h3>
    	<!-- begin index of issue -->
    	<?php query_posts('showposts=-1&<?php index_control_date ?>&cat=-3,-4'); ?>
    	<?php while (have_posts()) : the_post(); ?>
    	<?php endwhile; ?><!-- end index of issue -->
    </div><!-- #issue-index -->

    Note the “index_control_date” function in the last loop’s query_posts. I’d like to generate this with a plugin that pulls the published date out of the first cat-4 (my “theme” category) post on the page. Then my third loop, the issue-index, will only display posts related to the current issue—or posts published the same day as the theme post.

    For an archive page I could have custom category template that lists all the theme posts. Each theme posts links to a page that mirrors the functionality of my custom home page template.

    I’d also need the plugin to get the published date of posts not in the theme category on single pages. I could then use that value to run a loop that shows the theme associated with that particular post.

    Does that make sense?

    Here’s my real problem: I don’t know how to write this plugin. Can a plugin even do this with query_posts. Is there an easier way to do an issue-based magazine site with WordPress? Any help?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Ian Stewart


    Theme Wrangler

    Well, I got my first page to work—without a plugin even.

    The first loop sets up two variables:

    <?php $control_month = get_the_time('m'); ?>
    <?php $control_year = get_the_time('Y'); ?>

    Then my “issue-index” loop is controlled by the following query:

    <?php query_posts("showposts=-1&year=$control_year&monthnum=$control_month&cat=-3,-4"); ?>

    Now for the single article page that shows the related theme-post before the article (I’m thinking I’ll have to move it there with the stylesheet) and my archive page which is really an archive of just the theme category, each title linking to a page that shows the theme, editorial and index of all posts from the same month and year. That’ll be a tough one.



    Did you ever resolve this issue? There are a lot of us who are very interested in how to use WP as a issue-based magazine CMS, and what you’ve posted here seems like a promising approach.

    If you’ve achieved success with this project, I for one would be grateful to know the details….

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Dynamic Date in query_posts’ is closed to new replies.