category.php displaying only 10 posts - wordpress

I want display 30 posts on category.php , but after 10 post loop is terminating where as i have more then 30 posts for particular category . I have tried on category.php with if(have_posts() )

Ohh i got answer .. It is simply SETTINGS -> READING -> Blog pages show at most

#Dibya
try this way to show the number of posts on category.php without affecting blog page
<?php
$query = new WP_Query('category_name=Category&posts_per_page=30');
if($query->have_posts()) : while($query->have_posts()) : $query->the_post();
if (has_post_thumbnail()) {
?>
<?php the_post_thumbnail(); ?>
<?php
}
?>
<h2><?php the_title(); ?></h2>
<?php
the_excerpt(); // or the_content(); for full post content
endwhile;endif;
?>

This can also be resolved using posts_per_page = -1 parameter in wp_query. By using this , you don't need to bother about the backend settings. This will always works.

Related

splitting same category post for different styling - wordpress

currently I am making a custom theme for my client and I am not a expert in this. My question is how to make different style for post from same category. Currently in my theme
Starting a New query for first post
<?php query_posts('showposts=1&cat=videos&offset=0'); if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
<div class="first-news">
<h2><a href="<?php the_permalink() ?><?php the_title(); ?></a></h2>
<?php if( has_post_thumbnail() ) { ?>
<?php the_post_thumbnail('video-thumb');?<?php} ?>
<?php $excerpt = get_the_excerpt(); echo string_limit_words($excerpt,8); ?>
</div>
<?php endwhile; else: endif; ?>
then again starting the same query for remaining 4 posts with another div and style
<?php query_posts('showposts=4&cat=videos&offset=1'); if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
<div class="second-news">
<h3><a href="<?php the_permalink() ?><?php the_title(); ?></a></h3>
<?php if( has_post_thumbnail() ) { ?>
<?php the_post_thumbnail('news-thumb'); ?><?php } ?>
<?php $excerpt = get_the_excerpt(); echo string_limit_words($excerpt,8); ?>
</div>
<?php endwhile; else: endif; ?>
this working perfectly, Is this correct? I think there may be a good solution which will query post only once and get the required number of posts from same category with different style.
What I want is on below image.
You should use the category template from wordpress.
Before loading your page, wordpress looks for the presence of specific templates, example from the page linked above.
1. category-slug.php
2. category-ID.php
3. category.php
4. archive.php
5. index.php
In order to activate “post formats” in WordPress 3.1+, you will need to open your theme’s functions.php file and paste the following code:
add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );
Note: aside, and gallery are not the only available post formats. The available list of post formats are:
aside – Typically styled blog format.
chat – A chat transcript.
gallery – A gallery of images.
link – A link to another site.
image – A single image.
quote – A quotation.
status – A short status update, usually limited to 140 characters. Similar to a Twitter status update.
video – A single video.
For the full list of post formats, refer to WordPress Codex.
Once you have added this code, you will see a new field in your post write panel in the right hand column where you see publish.
Upon writing the post, you can change the format and hit publish. This will allow you to display your post in a pre-styled format.
Edit your post loop.
Suppose in your case videos category post format is video
We are going to be utilizing the conditional tag: has_post_format()
if ( has_post_format( 'video' ) {
// Blog Category format
}
else
{
// Normal Formate
}
I hope this will help you. More Info...

Category title display issue in Wordpress

I have the code below for a category in WordPress. It displays the name of the category when I want it to be displaying the title of the post. How do I get it to display the title of the post proper.
<? query_posts('category_name=implants');
?>
<h3><?php single_cat_title(); ?></h3>
<?php if (have_posts()) : while (have_posts()) :
the_post(); ?>
<?php the_content( __('Read the
rest of this page »', 'template')); ?>
<?php endwhile; endif; ?></p>
Do not use query_posts unless your intention is to modify the
default Wordpress Loop. Use WP_Query instead for standard Wordpress
queries.
Look at your code. You're calling single_cat_title(). It means
exactly what it looks like: You're pulling the title of the queried
category. You want to call the_title() to grab the post title.
Not as important as the above, but your opening tag is <? rather
than <?php. You should make it a habit of specifying your server-side language to avoid potential future problems, even though it might not be initially apparent.
Here's what your revised loop should look like:
<?php
$query = new WP_Query('category_name=implants');
if($query->have_posts()) : while($query->have_posts()) : $query->the_post();
?>
<h3><?php the_title(); ?></h3>
<?php
the_content( __('Read the rest of this page »', 'template'));
endwhile; endif;
wp_reset_postdata();
?>

Wordpress post query not adding <!--more-->

I'm trying to have a post from a certain category display on my static homepage.
I seem to everything working just how I'd like with one exception.
I'd like the post to included the standard Continue reading (<!--more-->) link, but I can't seem to get it to work on my homepage instead all the post's content is displayed.
Here's the code I'm using to display the one post from a catagory on my home page:
<?php $recent = new WP_Query("cat=4&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
<h2><?php the_title(); ?></h2>
<?php the_content( __( 'Continue reading →')); ?>
<?php endwhile; ?>
How do I get the <!--more--> tag to work correctly with the above code?
The <!--more--> quicktag generally doesn't work on anything other than the Home page. Try following the advice here under "How to Read More in Pages", i.e. like this:
<?php
global $more;
$more = 0;
?>
//The code must be inserted ahead of the call to the content
Then continue as you were:
<?php $recent = new WP_Query("cat=4&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
<h2><?php the_title(); ?></h2>
<?php the_content( __( 'Continue reading →')); ?>
<?php endwhile; ?>
You'll need to set $more to 0 before every the_content() call;
It resets every time it hits the loop.
The discussion topic referenced from that Codex entry talks about exactly the problem you're solving, I think.
I was able to find some information here: http://codex.wordpress.org/Function_Reference/the_content
Found these lines which seem to do the trick:
global $more; // Declare global $more (before the loop).
$more = 0; // Set (inside the loop) to display content above the more tag.
the_content("Read More");
Added the information to my code and everything work! Added in the Read More link when the more tag was added to the post.
Here's my final code:
<?php $recent = new WP_Query("cat=4&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
<h2><?php the_title(); ?></h2>
<?php global $more;
$more = 0;
the_content("Read More");
?>

Wordpress : List posts in category on '.com/categoryname' and display post on '.com/categoryname/post-name'

I have a permalink structure of /%catergory%/%postname%/.
When I go to blah.com/categoryname I want all posts in that specific category to be listed.
When I go to blah.com/categoryname/post-name I want just the specific post to be displayed.
I have made a category specific template (category-5.php) and have got as far as...
// Display all post titles in category loop
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php endwhile; ?>
<?php endif; ?>
// Display specific post in category loop
<?php if ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<div class="storycontent">
<?php the_content(); ?>
</div>
<?php endif; ?>
...but obviously I only want the first loop to display when the url is blah.com/categoryname, and the second loop to display when the url is blah.com/categoryname/post-name.
Any thoughts? thanks
You can't have two loops running on the same page as you do here.
I believe you need to separate out the two things you're trying to do. To have a unique look/feel for the category, create a category-1.php file. To create a unique look/feel for the posts within that category, create a separate 'single' template.
This WP support thread explains how to create the 'single' template: http://wordpress.org/support/topic/266638
There are also a few "post template" plugins that help accomplish the same thing, if you prefer to go that route, for instance:
http://wordpress.org/extend/plugins/post-template/
Full list here: http://wordpress.org/extend/plugins/search.php?q=post+templates
Good luck!

Display Wordpress Archives one category at a time?

I am almost done with my humble attempt at a custom CMS using Wordpress. The only difficulty I have is making a page display the archive for only one category (and it's children). Anyone has an idea?
Thanks a lot!
Regis
You can create your own custom archive page using the class WP_Query. Specifically, something like:
<?php $query = new WP_Query('category_name=code'); ?>
<?php while ($query->have_posts()) : $query->the_post(); ?>
<!-- display the category here -->
<?php endwhile; ?>
You can look at the default theme's archive.php to get a feel for what else is needed to display a particular category in a layout you are familiar with.
This is what I use to show a list of titles and permalinks for the category "mycategory"; this can go inside the main Wordpress loop:
<?php $my_query = new WP_Query('category_name=mycategory&showposts=-1'); ?><?php while ($my_query->have_posts()) : $my_query->the_post(); ?><?php the_title(); ?><?php endwhile; ?>
Change the "-1" to "1" to show only the one most recent post; to "10" to show the last 10 posts, etc.

Resources