Getting a list of all ID's on the site - wordpress

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

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.

Wordpress loop iterates over the last 15 posts only

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.

wordpress navigation issue. previous and next posts link return blank

I have the following issue with a theme I am developing:
in my index this code
<?php previous_posts_link(); ?>
<?php next_posts_link(); ?>
returns blank results...
if instead i use
<?php previous_post_link(); ?>
<?php next_post_link(); ?>
it shows the next post (a single page). Why is that you think? Any idea?
I use the above within the loop.
On the face of it the difference is only the slightly different spelling. The actual difference is that previous_posts_link should be used outside the loop, providing a means to paginate through posts i.e. view/page/2 where page 2 can be taken into a query_posts call getting the next batch of posts.
Whereas previous_post_link/next_post_link should be used inside the loop, providing a link to previous/next post in the publish chronology.
http://codex.wordpress.org/Function_Reference/previous_posts_link
http://codex.wordpress.org/Template_Tags/previous_post_link

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