<?php query_posts('showposts=3&cat=-4'); /* Specifies only 3 posts shown */ ?>
If I change it to showposts=2, is displays 3 and so on??
Any Ideas?
Thanks
]]>Here are two examples:
https://www.abandf.com.au/insurance/
https://www.abandf.com.au/newzealand/index.php
This is the code I am using:
<?php
// Include WordPress
define(‘WP_USE_THEMES’, false);
require(‘../news/wp-load.php’);
query_posts(‘showposts=5’);
query_posts(‘cat=1’);
?>
I hope someone can point out where I am going wrong. Thanks in advance for any help provided.
]]>when you click a section (category) – let’s just look at “print,” it shows the problem the best: https://ankatankdesign.com/makes/some/print/
it’s returning only the top ten projects (posts) in the section (category). there should be 11 showing. that number will grow though, and I’d like there to be no limit, no pagination, just a page that’s as long as it needs to be to show all the posts.
my “sidebar-right.php” code is what is displaying the categories on the print page that we’re looking at. Can anyone see from my sidebar code, what I would need to do/change make it show all posts, not just the ten most recent? thanks in advance!
the sidebar code is:
<div id="secondary" class="sidebar-CAT">
<?php $cat_title = single_cat_title('',false);
if (!$cat_title=='') {
if ( !empty($categorydesc) ) echo apply_filters( 'archive_meta', '<div class="archive-meta">' . $categorydesc . '</div>' );
}
?>
<?php
if(is_single()) {
$category = get_the_category();
query_posts('category_name=' . $category[0]->cat_name);
} else {
query_posts('category_name=' . single_cat_title(false, false));
}
while (have_posts()) : the_post(); ?>
<div id="sidebarCAT"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><img src="https://www.aaank.com/images/post_thumbs/<?php $values = get_post_custom_values("theThumb"); echo $values[0]; ?>" alt="<?php the_title(); ?>" /></a>
<div class="underThumbTxt"><?php if (strlen($post->post_title) > 15) {
echo substr(the_title($before = '', $after = '', FALSE), 0, 15) . '...'; } else {
the_title();
} ?></div>
</div>
<?php endwhile; wp_reset_query(); ?>
<br style='clear:both;' />
</div>
]]>I’m not sure what I’m doing wrong here because this works fine on my local site. I’m trying to launch my first blog and get this error from the home page:
Warning: Missing argument 1 for WP_Query::query(), called in https://blog.greggwatt.com/wp-content/themes/hybrid-custom/cross-home.php on line 49 and defined in https://blog.greggwatt.com/wp-includes/query.php on line 2512
I have a custom template for the home page (cross-home.php) to display the first 4 posts except posts from the featured category (ID=3).
Here is the code from the cross-home.php starting at line 49:
<?php
$wp_query = new WP_Query('showposts=4&cat=-3');
/* Show only first four posts on home page */
$wp_query->query();
$more = 0;
?>
<?php if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
Any idea what I could be doing wrong? I appreciate any help.
Cheers,
Gregg
I want a code where I can show only the title of posts from a specific cat and they have to be before the last 5 posts in the same cat.
Would that be possible?
]]>It works on the first page of the front page, it only shows posts from the last issue (last day that posts were posted). If I click on ‘older entries’ things start getting to go wrong.
The post-limit of the first page (day/issue) is used, instead of the limit of the page (day/issue) shown. That’s because I base the date on ‘$posts[0]->post_date’, which is the first post in the posts object. That object holds always all latest posts, also on front pages two and beyond.
To fix my problem I need a way to determine the array-number of the post with which the frontpages 2 and beyond starts their loop, so I can use that to get the date of the proper post. Like ‘$posts[18]->post_date’ for example, where ’18’ is the array number.
<?php // change post limit to show posts of only one day
if (is_front_page()) {
//get date of first post
$cpd=mysql2date('Ymd', $posts[0]->post_date);
//get all posts from that date
$posts_of_day=get_posts('year=' .substr($cpd, 0, 4) .'&monthnum=' .substr($cpd, 4, 2) .'&day=' .substr($cpd, 6, 2).'&showposts=1000');
//Count the amount of posts of that date
$daylimit=count($posts_of_day);
//limit the amount of posts that are shown accordingly
query_posts($query_string . "&showposts=".$daylimit);
} ?>
]]>For some reason, the showposts parameter isn’t working, when I specify the category. For example, if I did just a regular
<?php
//The Query
query_posts('showposts=9');
if (have_posts()) {
while (have_posts()) {
...
}
}
wp_reset_query();
?>
It works fine, and shows nine posts, but if I do
<?php
//The Query
query_posts('category_name=The Category Name&showposts=9');
if (have_posts()) {
while (have_posts()) {
the_post();
cfct_template_file('content', 'third');
}
}
wp_reset_query();
?>
All it does is display that category. I’ve also tried using ‘cat=111’, and ‘posts_per_page=9’, but they both just show the entire category. When I exclude categories it works fine though.
]]>On my home page the theme displays recent posts in different formats i.e. the most recent two within a larger feature block, the next 4 in a smaller block and the rest as a list. The original code looked like this:
query_posts( 'showposts=2' );
if (have_posts()) :
while (have_posts()) : the_post(); $category = get_the_category();
However, I want to exclude any “news” posts in the query. Unfortunately, the solution I came up with results in duplicate articles in each segment block as you can see on my site https://www.cinemadiving.com.
The change I made:
query_posts( array(
'showposts' => '2',
'cat' => '-20,-18') );
if (have_posts()) :
while (have_posts()) : the_post(); $category = get_the_category();
I would be extremely grateful if anyone could help with this?
]]>I am running two loops because I have some wacky CSS. In any case, there is something weird happening with my code. I need the first loop to show three unique posts and then the final loop to show just one unique post from the same category. It’s like I need some sort of limiter on the second loop. Here’s what I have:
<?php $my_query = new WP_Query('category_name=News&showposts=4');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate[] = $post->ID ?>
<!-- Do stuff... -->
<?php endwhile; ?>
<!-- Do other stuff... -->
<?php if (have_posts()) : while (have_posts()) : the_post();
if (in_array($post->ID, $do_not_duplicate)) continue;
update_post_caches($posts); ?>
<!-- Do stuff... -->
<?php endwhile; endif; ?>
Thanks!
]]>Ultimately, the basic code to do so is:
<?php while (have_posts()) : the_post();
if (has_tag('Twitter') && is_home() ) continue;
?>
Thus, if the post has the tag (in this case, “Twitter”) and this is the home page, then it will skip it.
(Hopefully this information is useful to someone else as well; there’s a lot of info about how to do this with categories, but not much with tags, which seem to work slightly differently.)
So, that’s the part I’ve solved — here is the part I have not solved: My query is set to show an exact number of posts:
<?php query_posts("showposts=6"); ?>
…and when I use the code shown above to exclude a post, it throws off the number of posts shown. For example, if, among those 6 posts, one is tagged “Twitter”, then only 5 posts are shown. If two are tagged “Twitter”, then only 4 posts are shown.
How to I exclude a post, yet keep the number of posts at 6?
]]>