Link to home
Create AccountLog in
Avatar of merchantweb2
merchantweb2

asked on

Need Help with Custom Wordpress Loops...

I have a wordpress site that is running the no future posts plugin so that all post will show up as published. I do this so the site viewers can use the calendar to browse future events. On the home page I am trying to show all post that happen on or before the current date and list them starting with today's date. One the events page I am only showing upcoming posts in the events category to simulate an upcoming events page. I also have an upcoming events and recent posts list in the sidebar. The url to the website I'm working on is http://www.keepfaithmoving.org

I thought I had all the code right but it seems that when we kept adding posts it started to mess up and now it is acting weird. Any help discovering the issue would be very helpful. I will post the code I am using on those pages.

 
index-loop.php
-------------------

<?php $my_query = new WP_Query("category_name=events,audio,video,articles&order=DESC");
    if ($my_query->have_posts()) {
        $i = 0;
        while ($my_query->have_posts() && $i < 100 ) : $my_query->the_post(); $do_not_duplicate = $post->ID;
    if (get_the_time('Ymd') <= date('Ymd')) : $i++; ?>
       
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
			<h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>

			<div class="entry-meta">
				<?php twentyten_posted_on(); ?>
			</div><!-- .entry-meta -->

	<?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?>
			<div class="entry-summary">
				<?php the_excerpt(); ?>
			</div><!-- .entry-summary -->
	<?php else : ?>
    
    <div class="entry-content">
<?php the_content('Read the rest of this entry &raquo;'); ?>
</div>
	
   <!-- .entry-content -->
	<?php endif; ?>

			<div class="entry-utility">
            <?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php comments_popup_link('Leave a Comment', '1 Comment ', '% Comments'); ?> <?php edit_post_link( __( 'Edit', 'twentyten' ),  '</span>' ); ?>
          <!--  <br />
				<?php if ( count( get_the_category() ) ) : ?>
					<span class="cat-links">
						<?php printf( __( '<span class="%1$s">Posted in</span> %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) ); ?>
					</span>
					<span class="meta-sep">|</span>
				<?php endif; ?>
				<?php
					$tags_list = get_the_tag_list( '', ', ' );
					if ( $tags_list ):
				?>
					<span class="tag-links">
						<?php printf( __( '<span class="%1$s">Tagged</span> %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list ); ?>
					</span>
					<span class="meta-sep">|</span>
				<?php endif; ?>
				<span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></span>
				<span class="meta-sep">|</span><span class="edit-link"><?php edit_post_link( __( 'Edit', 'twentyten' ),  '</span>' ); ?>-->
				</div><!-- .entry-utility -->
		</div><!-- #post-## -->

<?php endif; endwhile; } ?>

Open in new window

events.php
-----------------
<?php
$my_query = new WP_Query('category_name=events&post_status=publish&order=ASC');
?>

<?php
if ($my_query->have_posts()) : while ($my_query->have_posts()) :
$my_query->the_post();
$do_not_duplicate = $post->ID;
    if (get_the_time('Ymd') >= date('Ymd')) : $i++; ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
			<h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>

			<div class="entry-meta">
				<?php twentyten_posted_on(); ?>
			</div><!-- .entry-meta -->

	<?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?>
			<div class="entry-summary">
				<?php the_excerpt(); ?>
			</div><!-- .entry-summary -->
	<?php else : ?>
    
    <div class="entry-content">
<?php the_content('Read the rest of this entry &raquo;'); ?>

</div>
	
   <!-- .entry-content -->
	<?php endif; ?>

			<div class="entry-utility">
            <?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php comments_popup_link('Leave a Comment', '1 Comment ', '% Comments'); ?> <?php edit_post_link( __( 'Edit', 'twentyten' ),  '</span>' ); ?>
          <!--  <br />
				<?php if ( count( get_the_category() ) ) : ?>
					<span class="cat-links">
						<?php printf( __( '<span class="%1$s">Posted in</span> %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) ); ?>
					</span>
					<span class="meta-sep">|</span>
				<?php endif; ?>
				<?php
					$tags_list = get_the_tag_list( '', ', ' );
					if ( $tags_list ):
				?>
					<span class="tag-links">
						<?php printf( __( '<span class="%1$s">Tagged</span> %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list ); ?>
					</span>
					<span class="meta-sep">|</span>
				<?php endif; ?>
				<span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></span>
				<span class="meta-sep">|</span><span class="edit-link"><?php edit_post_link( __( 'Edit', 'twentyten' ),  '</span>' ); ?>-->
                
<!--                <?php
echo 'comment count is: ' . $post->comment_count;
 // Restore global post data stomped by the_post().
?>
-->
				</div><!-- .entry-utility -->
              



		</div><!-- #post-## -->
<?php endif; endwhile;?>

 
<?php endif; ?></div>

Open in new window

sidebar.php
---------------

<div id= "eventbx"><span class="event_heading">UPCOMING EVENTS</span>
<ul style="list-style-type:none;padding: 0;margin-left: 0;">
<?php
$my_query = new WP_Query('category_name=events&post_status=publish&order=ASC&showposts=5');
?>

<?php
if ($my_query->have_posts()) : while ($my_query->have_posts()) :
$my_query->the_post();
$do_not_duplicate = $post->ID;
    if (get_the_time('Ymd') >= date('Ymd')) : $i++; ?>
 
<li> <?php the_time('n/j')?>&nbsp;-&nbsp;<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permalink to <?php the_title(); ?>"><?php the_title(); ?></a></li>
 
<?php endif; endwhile;?>

 
<?php endif; ?>
</ul></div>


<div style="height:30px;clear:both;"></div>

<div id= "eventbx"><span class="event_heading">RECENT POSTS</span>
<ul style="list-style-type:none;padding: 0;margin-left: 0;">
<?php
$my_query = new WP_Query('category_name=articles,video,audio&post_status=publish&order=DESC&showposts=5');
?>

<?php
if ($my_query->have_posts()) : while ($my_query->have_posts()) :
$my_query->the_post();
$do_not_duplicate = $post->ID;
    if (get_the_time('Ymd') <= date('Ymd')) : $i++; ?>
 
<li><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permalink to <?php the_title(); ?>"><?php the_title(); ?></a></li>
 
<?php endif; endwhile;?>

 
<?php endif; ?>
</ul></div>

Open in new window


If anyone could point out my mistakes and help me work this kink out , that would really help me on this project. Thank you!
Avatar of merchantweb2
merchantweb2

ASKER

anyone?
Do you have a link to an example of where "it started to mess up and now it is acting weird"?
Here is my test server where I thought it was all working but that was before I added more posts.: http://secundsun.com/wordpress3

Ok, the home page should be showing the 5 latest posts under the welcome message. These would be the same 5 posts that appear under recent posts in the sidebar. Also, the upcoming events in the sidebar should show the next 5 upcoming events.

On keepfaithmoving.org we have added many more events and posts but it seems to not display correctly, the more posts we add.

Right now if you go to keepfaithmoving.org, none of the upcoming events are displaying under the sidebar section for events, yet on the events page you will see that there are 6 future events.
???
Did you get the upcoming events fixed because when I go to your events page I see the the same future events listed in both the posts and the sidebar.

http://keepfaithmoving.org/?page_id=13

And the recent posts in the sidebar appears to be working correctly too.  The most recent posts that aren't events are listed.
If you are trying to exclude the category "events" from the posts under the welcome message so that they match your 'Recents Posts' list in the sidebar then make your query $args the same

in index-loop.php you have category_name=events,audio,video,articles

but in sidebar.php you have category_name=articles,video,audio

ASKER CERTIFIED SOLUTION
Avatar of merchantweb2
merchantweb2

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Jason C. Levine
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.