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.
Related
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.
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
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
in Wordpress on a post how can I get the name of the category it belongs to (each post will only have one category on my website).
The version of wordpresss you're using is very much relevant for your question, but a good place to start would be the wordpress codex where you can find for example the documentation of this function.
It is also important to know whether your code will be placed within the infamous loop (which would be the case if you're editing the post template) or not (for example, if your code goes at the sidebar, header, etc).
Assuming the first case, and taking the example from the manual, you could use:
<?php
$categories = get_the_category();
// there is only one, so extract the first from the array
$category = $category[0];
?>
These can go in header.php for generating meta tags, page titles, etc.
<?php echo trim(strip_tags(category_description())); ?>
<?php echo single_cat_title(''); ?>
Also see Template Tags/single cat title « WordPress Codex
I use Barecity Theme for WordPress. i built everything, but now i need to add a single.php file to theme. now it displays all post content at homepage, I created a short_desc Custom Field. and I call it from code with;
<?php //get_post_meta($post->ID, 'short_desc', true); ?>
it is fine. but i need to display this short desc at home page listing, and the main content at details page. how can do that?
I appreciate helps!!
It sounds like what you are trying to do is show a custom field that you have set on a post on the index page (which lists all the posts).
To do that you'll need to modify index.php by adding your snippet where you would like to have the short description.
<?php echo get_post_meta($post->ID, 'short_desc', true); ?>
You need to use echo to display the results from the get_post_meta function.
Depending on how your posts are setup you can also use the More button when you write your posts. This will cut off your post at a certain point that you decide and only show that short part on the index and archive pages.
Another option would be to use
<?php the_excerpt(); ?>
Which shows the first 55 words (this can be adjusted though) of the post.
Hope that helps,
Paul