Wordpress loop iterates over the last 15 posts only - wordpress

I'm using a wordpress framework (WooFramework) that uses the following code to create a list of all posts of a specific category:
<?php while ( have_posts() ) { the_post(); ?>
<li><?php the_title(); ?></li>
<?php } ?>
I check the Wordpress documentation and this code seems right. However the list outputted contains only the 15 most recent posts. It seems like something is making the have_posts() stop earlier than it should. Any ideas on what may be causing this problem?
Tip: The index page shows (by default) the 15 most recent posts. Can that be related with the problem? Could it be possible that the framework redefined wordpress' have_posts() function?

Try going to Settings > Reading and changing the value of "Blog Pages Show At Most". If you want to show all your posts you can just set it to something really high like 9999999999.

Related

Why i need a wp loop in single.php

In WordPress theme development we can use single.php to show the specific single post.
For this purpose the common practice is:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php the_content();?>
<?php endwhile; ?>
<?php endif; ?>
Why do I need looping to show a single post? Can any one give some valid reason?
this was something that killed me for years and I found the answer:
No, you don't need to use the LOOP in single pages, you just call the_post() and you have all data needed
.... BUT ....
If you don't use the loop (while(have_posts())....) a hook "loop_end" is not called and if a plugin/process has any action on this hook, it won't work. So for safety reasons you should use the loop.
Also, people ask do I need to check for existence before the loop: if(have_posts())?
<?
if( have_posts() ):
while( have_posts() ):
the_post();
.....
endwhile;
endif
?>
No, you don't need to check
.... BUT ....
Checking allows you to include headers/titles before the loop and not having them if the loop is empty.
The WordPress Loop instantiates some functions like the_title(), the_content() and others.
In other words, your post is loaded in that loop, and the loop is gone through once if you are on a single post. Although it might be strange to have a loop, it is actually quite useful.
WordPress uses a template hierarchy, which is a way of choosing which template to load for a given post/page. In your single.php, the loop will run once. But if you do not have a single.php file, WordPress will use index.php instead for that same post.
For the sake of consistency, having a loop which works for any number of posts is helpful. Else, in you index.php, you would have needed a case for one post and another case for multiple posts and keeping a consistent templating method would be difficult.

Getting a list of all ID's on the site

Sounds inane, but I think it would be handy to have an id list of the name of every element on my site. By every element I mean Posts, Pages, Comments, Users, the works.
Id, Title
That's it.
I do not know how to loop through PHP code for this. My PHP skills are weak. Is this too ridiculous to answer? Maybe, but I'd still find it handy. I've looked through every Plug-in name and description that was close to fitting this task and found nothing.
Thanks,
Mike
The Loop is used by WordPress to display each of your posts. Using The Loop, WordPress processes each of the posts to be displayed on the current page and formats them according to how they match specified criteria within The Loop tags. Any HTML or PHP code placed in the Loop will be repeated on each post. When WordPress documentation states "This tag must be within The Loop", such as for specific Template Tag or plugins, the tag will be repeated for each post.
For example, among the information The Loop displays by default: the Title (the_title()), Time (the_time()), and Categories (the_category()) for each post. Other information about each post can be displayed with the appropriate Template Tags or (for advanced users) by accessing the $post variable, which is set with the current post's information while The Loop is running.
Simple Example:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
What you need to use is the_id() function. It displays the numeric ID of the current post. This tag must be within The Loop.
Put something like this in your loop
<p>Post Number: <?php the_ID(); ?></p>
References:
http://codex.wordpress.org/Function_Reference/the_ID
http://codex.wordpress.org/The_Loop

Adding a second loop to a Wordpress theme on a separate page

I'm trying to add two loops to a theme on two separate pages: home and blog.
Blog is basically an index of the posts. It's what most Wordpress pages default to as a home page. To accomplish this I went to "reading settings" and set "front page displays" as 'static' with "front page" set to a Home page I set up in Wordpress pages and "posts page" set to a Blog page.
Now the problem is that when I add the loop to the Home page, it doesn't work, presumably because I have posts page set to a different page.
So how do I get the loop to work on the Home page as well as the blog page? Btw, the Home page loop is just post title + date + maybe excerpts. Do I need to completely rework the theme or is this is just not a possibility under Wordpress?
Oh and the loop I'm using is:
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post() ?>
There are at least three wayst to run custom queries in WordPress.
Query_posts() can define the query string of your second loop. It is easy and very common to do. This code is a basic structure I copied from the codex page for query_posts():
//The Query
query_posts('posts_per_page=5');
//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
..
endwhile; else:
..
endif;
//Reset Query
wp_reset_query();
You can also use get_posts() which is similar.
<ul>
<?php
global $post;
$myposts = get_posts('numberposts=5&offset=1&category=1');
foreach($myposts as $post) :
setup_postdata($post);
?>
<li><?php the_title(); ?></li>
<?php endforeach; ?>
</ul>
Both functions accept a number of arguments that are explained on the query_posts function reference page. The arguments shown above are only examples. The list of available args is long.
A third method available to you is to instantiate another instance of the WordPress Query object (WP's main query method). Query_posts and get_posts both run a second call to the database after WordPress runs the default wp_query. If you are super concerned about performance or reducing db hits, I suggest learning how you can interact with wp_query to modify the default query before it is run. The wp_query class provides a number of simple methods for you to modify the query.
Good Luck!
It is possible that WordPress does not start a loop for you because you use a static page. But if this static page is defined in your theme (since you include the PHP code to display the loop, I assume it is), you can always start a new loop there yourself. Just call query_posts yourself, and your code should start working.

Wordpress: Removing posts in "The Loop" using filters

After reading the Wordpress documentation, I realized you can remove posts from the index using filters inside "The Loop", e.g.:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<!-- The following tests if the current post is in category 3. -->
<?php if (in_category('3')) continue; ?>
<!-- display normal post -->
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
What I'm wondering is if there is a filter/hook to filter posts in have_posts() without modifying the template. So far, I found options to change the results, but not remove results form the result set.
You can hook into 'pre_get_posts'.More info here: http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts. As the article describes:
This hook is called after the query variable object is created, but before the actual query is run.
Using query_posts(), you can override the query variables and exclude any posts. The link has some decent examples on how to do this.
So you want to remove it from displaying but still have it 'there' incase you decide to show it later? Not really clear on what you want to do.
As one example, in the past I've used Query Posts to keep categories off of my homepage: http://codex.wordpress.org/Template_Tags/query_posts#Exclude_Categories_From_Your_Home_Page

Display Posts from a category in Wordpress?

I am trying to display just post title and their links within a set category. However I am running into issues understanding the Codex. Any help or guidance would be greatly appreciated.
I use this a lot in my blogs. Helpful when you want to display featured items or such.
http://codex.wordpress.org/Template_Tags/query_posts#Category_Parameters
http://codex.wordpress.org/The_Loop#Style_Posts_From_Some_Category_Differently
You might have seen the above link. I'll explain how it works.
Posts are loaded using the loop. If you do a Query Posts just before the loop, you can choose from select category (or many categories) and also limit the number.
<?php query_posts('cat=1&showposts=5'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li><?php the_title(); ?>
<?php the_excerpt() ?>
</li>
<?php endwhile; endif; ?>
You can use the above code as many times you wish. Choose the category ID (can be found from the admin) and the number of posts you wish to show.
Comment - if you require additional help.
It seems that you are working on your templates. It basically means that you need to edit correct template and insert the right tags.
Firstly, you need to understand how the template is chosen. WP has special hierarchy for every view. Home page is usually home.php and categories are category.php or category-1.php. If any file is missing, WP simply takes next on the list. Last on the hierarchy list is index.php which is chosen if no other file is found.
[http://codex.wordpress.org/Template_Hierarchy#Category_display][1]
Secondly, look at the template tags. Displaying only title with link means you need title and permalink tag. Anything else is optional.

Resources