Display post on Pages
-
I have created a page and edited the page.php file with my custom template.
I am wanting to display post from a certain category here, how am I able to do so?
Thanks in advance!
-
You need to create a custom page template that uses either get_posts or query_posts.
See if there is anything helpful here;
oops.. I have the slows today. ??
here is my code:
<?php /* Template Name: Product Catalog */ ?> <?php get_header(); ?> <!-- header include --> <div id="left"> <div id="left-top"> <h2>Product Catalog</h2> </div><!-- end left-top --> <div class="blog-content"> <?php query_posts('cat=3&showposts=3&order=ASC&orderby=post_title'); ?> <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?> <!--<h2><?php //the_title(); ?></h2>--> <p> <?php the_content(); ?> </p> <?php endwhile; ?> </div><!-- end blog-content --> <?php else : ?> <div class="post" id="post-<?php the_ID(); ?>"> <h2><?php _e('Nothing Here'); ?></h2> </div> <?php endif; ?> <div class="catalog-pages"> <p> <?php posts_nav_link('<span style="padding-left: 450px"></span>','Previous','Next'); ?> </p> </div><!-- end catalog-page numbers --> </div><!-- end left --> <?php get_sidebar(); ?> <!-- sidebar include --> <?php get_footer(); ?> <!-- footer include --> </div> <!-- wrap end --> </body> </html>
I added your query_post idea and it didn’t seem to work.
In what way didn’t it work? I assume you did apply this template to a published page, yes?
yep sure did, none of the post are appearing
I can’t see anything wrong with that query – other than you might want to change
showposts
toposts_per_page
(showposts
is now deprecated). Could the category id be incorrect? You could try using something like:<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args= array( 'category_name' => 'Name, 'posts_per_page' => 3, 'order' => 'ASC', 'orderby' => 'post_title', 'paged' => $paged ); query_posts($args); ?>
which would let you use the category and ensure functional paging. Or, as it’s a single category, you could look at creating a category template.
I have added your script at the top replacing:
<?php query_posts('cat=3&showposts=3&order=ASC&orderby=post_title'); ?> <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
Still nothing showing
Also, reason I created page, is i want to make the category password protected.
<?php query_posts('cat=3&showposts=3&order=ASC&orderby=post_title'); ?> <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
That seems to work fine for me. I changed the category and the sort order just to be sure.
got it to work, not sure what the issue was but thanks for the help.
Now i am recieving a new error about my header:Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at /public_html/blog/wp-content/themes/mytheme/productcatalog.php:9) in /public_html/blog/wp-content/themes/mytheme/header.php on line 2
My line two is the following:
/*
Which is part of the template declaration.
Whats up now?
Also my posts_nav_link arent working.
Got the “Warning…..” error fixed.
But I am back to getting this error:
Parse error: syntax error, unexpected T_ENDIF in public_html/blog/wp-content/themes/mytheme/productcatalog.php on line 67
On line 67 is </html>
here is my code:
<?php /* Template Name: Product Catalog */ get_header(); ?> <!-- header include --> <div id="left"> <div id="left-top"> <h2>Product Catalog</h2> </div><!-- end left-top --> <div class="blog-content"> <?php query_posts('cat=3&showposts=3&order=ASC&orderby=post_title'); ?> <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?> <h2><?php the_title(); ?></h2> <p> <?php the_content(); ?> </p> <?php endwhile; ?> </div><!-- end blog-content --> <?php else : ?> <div class="post" id="post-<?php the_ID(); ?>"> <h2><?php _e('Nothing Here'); ?></h2> </div> <?php endif; ?> <?php $pagelist = get_pages('sort_column=menu_order&sort_order=asc'); $pages = array(); foreach ($pagelist as $page) { $pages[] += $page->ID; } $current = array_search($post->ID, $pages); $prevID = $pages[$current-1]; $nextID = $pages[$current+1]; ?> <div class="catalog-pages"> <?php if (!empty($prevID)) { ?> <p> <a href="<?php echo get_permalink($prevID); ?>" title="<?php echo get_the_title($prevID); ?>">Previous</a> </p> <?php if (!empty($nextID)) { ?> <p> <a href="<?php echo get_permalink($nextID); ?>" title="<?php echo get_the_title($nextID); ?>">Next</a> </p> </div><!-- end catalog-pages --> </div><!-- end left --> <?php get_sidebar(); ?> <!-- sidebar include --> <?php get_footer(); ?> <!-- footer include --> </div> <!-- wrap end --> </body> </html>
What is causing this error?
- The topic ‘Display post on Pages’ is closed to new replies.