Forum Replies Created

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter mattyscribs

    (@mattyscribs)

    thank you! sorry I am just getting to this now.

    Thread Starter mattyscribs

    (@mattyscribs)

    I found my answer — must place

    <?php wp_reset_query(); ?>

    after each query.

    this topic can be resolved now. thanks again for your help esmi.

    Thread Starter mattyscribs

    (@mattyscribs)

    Hi Esmi – hate to be a bother but do you have any other suggestions? Otherwise, I’ll have to find a work-around and move on.. thanks again for your help.

    Thread Starter mattyscribs

    (@mattyscribs)

    thanks but doesn’t work..sorry :{

    Thread Starter mattyscribs

    (@mattyscribs)

    thanks I think that all makes sense to me, but I am still having a problem –

    my home page is correctly using my “home.php” template, but in my sidebar, I have the following logic:

    <?php if ( is_front_page() || is_page() ) { ?>
    <!-- DO THIS -->
    <?php } else { ?>
    <!-- DO THAT -->
    <?php } ?>

    Now for some reason, the following code (which is in home.php) flips the switch in the logic above in my in the sidebar.
    <?php query_posts('category_name=blog&showposts=1'); ?>

    That piece of code makes my sidebar display “DO THAT” — when I remove it I get the “DO THIS” stuff. So something about the code is making the php think that I cam on an archive blog page or something, when I want it to think I am on my front page.

    Thanks for your help and I hope this makes sense.

    Thread Starter mattyscribs

    (@mattyscribs)

    esmi – I am hoping you could continue to help me with something related – although the code I have above does work, it has somehow messed up the current page definition. In my sidebar on my homepage, it now says: ‘You are currently browsing the archives for the Legislative Issues category.’, which is in fact the last looped content on my page.

    For some reason the loops are causing the WP application to think I am on an archive page, which is messing up my template assignments, ie. the static homepage is using the page.php instead of the home.php file, and the is_front_page() doesn’t resolve true for the sidebar code I have going on.

    So I think maybe I need to close my loops in some way?

    Thread Starter mattyscribs

    (@mattyscribs)

    thanks esmi — well I am new at all this.. I have managed to get things working thanks to your advice. One of my main issues was that I was trying to make all this happen on a static page, so I read up on that stuff and it helped. Finally, I played around and poked and got things to work the way I wanted. Here is what I came up with – this is for a static homepage which displays categorized posts in different places on the page, with the more tag working and your ‘islast’ type test to help with display.

    First, set the global $more variable at the top of the page, under the header include:
    <?php global $more;?>

    Then this will display the first looped content for my blog category, straight-forward enough, I just want to display the latest blog post here. Note how the ‘$more’ variable is referenced – this will be the same for all instances:

    <?php query_posts('category_name=blog&showposts=1'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    	<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>" class="title"><?php the_title(); ?></a><br />
    	<small><?php the_time('F jS, Y') ?></small>
    	<?php
    		$more = 0;
    		the_content("<b>Read More &raquo;</b>");
    	?>
    <?php endwhile; else: endif; ?>

    …And then to display may articles I did this:

    <?php rewind_posts(); $c = 0; $toshow = 4; query_posts('category_name=articles'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    	<?php if ( !in_category('6') && ($c < $toshow) ): ?>
    		<?php $c++; ?>
    		<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>" class="title"><?php the_title(); ?></a><br />
    		<small><?php the_time('F jS, Y') ?></small>
    		<?php
    			$more = 0;
    			the_content("<b>Read More &raquo;</b>");
    		?>
    		<?php if($c < $toshow):?><hr /><?php endif; ?>
    <?php endif; endwhile; else: endif; ?>

    This has the “islast” logic (sorry I keep calling it that). I call a rewind_loop function before the query. I also had to reconstruct the logic of ‘showposts’ and ‘category_name’ so I could not display one category, but keep the counters working the way I wanted. I then have the one category I omitted here to display in yet another loop further down on the page, like so:

    <?php rewind_posts(); $c = 1; query_posts('category_name=legislative&showposts=2'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    	<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>" class="title"><?php the_title(); ?></a><br />
    	<small><?php the_time('F jS, Y') ?></small>
    	<?php
    		$more = 0;
    		the_content("<b>Read More &raquo;</b>");
    	?>
    	<?php if($c<3):?><hr /><?php endif;?>
    	<?php $c++; ?>
    <?php endwhile; else: endif; ?>

    Here I use the category_name and showposts normally, since I don’t have the constraints I needed for the previous loop.

    I hope this is helpful to someone out there – took me a while to figure it out πŸ˜‰ If you have any improvements on syntax or logic, I’d be happy to hear.

    thanks again esmi!

    Thread Starter mattyscribs

    (@mattyscribs)

    I have since found this link which works for me:

    http://www.texto.de/how-to-pages-that-display-all-posts-from-x-category-522/

    which uses this query:

    <?php rewind_posts();
    $my_query = new WP_Query('category_name=articles&showposts=2');
    while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID;
    global $more;
    $more = 0; ?>

    .. which appears to be the old way when I would rather use this way:

    $posts=get_posts('category_name=articles&showposts=2');
    foreach($posts as $post) {
    setup_postdata($post);
Viewing 9 replies - 1 through 9 (of 9 total)