Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
$5
Category posts displaying on different pages
I am trying to create a theme for someone so they can easily update their site. They will need to update testimonials & news themselves.
I have created the category 'news' and 'testimonials' but I need these to display on a certain page, not "wordpress/category/news/".
I am expecting to create a new page template to achieve this, but cant find the actual syntax to only get certains posts within a certain category to display.
Quick response would be great!
This question has been answered.
Luke Zammit | 07/19/12 at 12:06pm
Edit
(5) Possible Answers Submitted...
See a chronological view of answers?
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
-

Last edited:
07/19/12
12:56pmLuis Abarca says:Use
<?php
$news_catID = 2; // change this with your news category ID
$posts = get_posts( array('category' => $news_catID) );
foreach( $posts as $post ) :
setup_postdata($post); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
Previous versions of this answer: 07/19/12 at 12:14pm | 07/19/12 at 12:56pm
-

Last edited:
07/19/12
12:16pmDbranes says:You can also check the examples here
http://codex.wordpress.org/Template_Tags/get_posts
to include in your template files
fx:
<ul>
<?php
global $post;
$args = array( 'numberposts' => 5, 'category' => 10 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) :
setup_postdata($post); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
where '10' is your category_id.
Previous versions of this answer: 07/19/12 at 12:16pm
-

Last edited:
07/19/12
12:25pmArthur Araújo says:Hi Luke, this is a solution:
1. Create a page in admin with the same slug as your cathegory;
2. Create a php template page, exemple: page-news.php
3. Place this code on the page-news.php:
$cat_ID = get_category_by_slug('news')->term_id;
query_posts( 'cat=' . $cat_ID );
include 'category.php';
And repeat the same steps to testimonials. -

Last edited:
07/19/12
12:35pmsabby says:Hi,
Paste this code in one raw file with the name of template_news and upload in your theme
<?php
/*
Template Name: News
*/
?>
<?php get_header(); ?>
<div id="content">
<h1 class="page-title"><?php the_title(); ?></h1>
<div class="entry">
<?php
query_posts(array('category_name' => 'category-slug', 'posts_per_page' => -1 ));
while (have_posts()) : the_post();
if(has_post_thumbnail()) {
the_post_thumbnail( array(180,200) );
}
echo the_title();
the_content('');
endwhile;
// Reset Query
wp_reset_query();
?>
</div>
</div>
</div>
<?php get_footer(); ?>
Once you paste this code go to add new page and in the page setting you will find the page as news. select it and update it will automatically display all news.
Only thing is that you need to copy your div tags whatever you have in a theme or give me your any theme file code.
In the same you can do this for : testimonials.
Previous versions of this answer: 07/19/12 at 12:35pm
- 07/20/12 6:35am
Luke Zammit says:Thanks everybody for your replies..
Arnav, I used yours first and it worked perfectly.
Thanks very much! I will vote later today.
- 07/20/12 6:35am
-

Last edited:
07/19/12
1:16pmArnav Joy says:try this
<?php
/*Template Name: News Template*/
get_header();
$news_category_id = 1; // enter category id for news category here
$showposts = 10; // -1 for all the posts
?>
<div id="primary">
<div id="content" role="main">
<h1><?php echo get_cat_name($news_category_id);?></h1>
<?php wp_reset_query();?>
<?php query_posts('cat='.$news_category_id.'&showposts='.$showposts);?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'theme' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<div class="entry-content">
<?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'theme' ) ); ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query();?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>
save the code as any file.php say news.php and then create a page and choose template "News Template" from the page attributes at right side ans see.
let me know if you need any help in this .
This question has expired.
Luke Zammit voted on this question.
Current status of this question: Completed
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
