Hi,
Please post code inside backticks (see the text at the bottom of the box you’re typing into)…
Looking at what you have, i can’t tell how many queries you have (code might be missing), but if it’s just the one i see, these 2 lines…
<?php if (have_posts()) : ?>
<?php query_posts("showposts=3"); ?>
Are actually the wrong way round… they should be..
<?php query_posts("showposts=3"); ?>
<?php if (have_posts()) : ?>
The first line query_posts.. sets the parameters for which posts to query, kind of like a where X = X thing…
The second line says “if this query has posts, then do….”
So logically they seem to be the wrong way round… but i could be missing something in your code, since you had a slight problem.. 😉 with the first go… 😉
Thread Starter
sabbry
(@sabbry)
I’ve made that change and I’m not seeing my test posts appear.
I can’t get // or comment block /* and */ to work on the forums. My LI and UL elements are being picked off by the forum system.
But here’s the code:
<div id=”upcomingacts”>
<li id=”recent_posts”>
<?php query_posts(“showposts=3”); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post();?>
- ” title=”<?php the_title(); ?>”><?php the_title(); ?>
<?php endwhile; ?>
<?php else : ?>
<h2 class=”center”>Not Found</h2>
<p class=”center”>Sorry, but you are looking for something that isn’t here.
<?php endif; ?>
</div><!– end of upcoming acts –>
You need to post code here inside 2 backticks (to the left of the 1 key – top left). No matter anyway.
The above code you’re using just simply grabs 3 non-specific posts…
What do you need it to do?
Thread Starter
sabbry
(@sabbry)
I need this function to grab the 3 most recent posts and order it from oldest post to the newest post. Right now, though, I’m just trying to query the 3 most recent posts.
<div id="upcomingacts">
<li id="recent_posts">
<ul>
<?php query_posts("showposts=3"); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post();?>
<li> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
<?php else : ?>
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.
<?php endif; ?>
</ul>
</li>
</div><!-- end of upcoming acts -->
This should do it for you.
<div id="upcomingacts">
<li id="recent_posts">
<ul>
<?php query_posts("showposts=3&orderby=date&order=DESC"); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post();?>
<li> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
<?php else : ?>
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.</p>
<?php endif; ?>
</ul>
</li>
</div><!-- end of upcoming acts -->
Not sure if you want old or new at the top, but you can change that with the query_posts. order=DESC will put newest at the top, and you can put the oldest at the top by changing DESC to ASC.
Thread Starter
sabbry
(@sabbry)
Cool. That function seems to work.
Is there any reason why my <li> and <ul>
items aren’t getting styled by CSS in the browser?
Dreamweaver recognizes that I’m styling PHP elements, but Safari, FF, and IE aren’t formatting the elements the same way. Which makes me wonder, is there a style sheet overriding my formatting?
Other elements of my design are formatted correctly by my CSS file.
Thread Starter
sabbry
(@sabbry)
When there are more than 3 posts, is it possible to query the most recent 3 and sort them in Ascending order (from oldest to newest)?
The code I’m using will not display my 4th and 5th post, for example. I need to manually delete the oldest post in order for it to work.
<div id="upcomingacts">
<li id="recent_posts">
<ul>
<?php query_posts("showposts=3&orderby=date&order=ASC"); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post();?>
<li> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
<?php else : ?>
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.</p>
<?php endif; ?>
</ul>
</li>
</div><!-- end of upcoming acts -->
Is there any reason why my
items aren’t getting styled by CSS in the browser?
You probably need to edit/expand your CSS.
Thread Starter
sabbry
(@sabbry)
Esmi,
The CSS file wasn’t replaced on upload. I’ve resolved the problem.
Thanks,
Sean