Do you know how to make a custom page template? You can make one just for that page to use and then use a custom query to pull up posts only for that category like so:
<?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query('category_name=shared'.'&paged='.$paged); ?> <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
Aha – I see.
Thanks. I’ll go away and try that right now.
First I’ve heard of the pastebin. I’ll go do that and come back here with the link or whatever.
Ok so what you would do is make a copy of your page.php file and rename it to something else, like page_shared.php. Then at the very top of the page paste:
<?php/*Template Name: Shared Page */?>
Upload that to the server and then when editing that page from the admin pick it as a page template.
Then replace the loop with the code that I gave you. Note that it starts with a “while” statement, no “if” so at the bottom of the loop make sure it ends only with
<?php endwhile; ?>. If there’s an endif; in there it will throw an error.
I’m sorry – I’m a real PHP newbe.
I done the template name bit and selected it. What I can’t work out is what a loop is?
Can you show me in the pastebin link? I would really appreciate it.
This is the code I have in the page template, but I get no posts shown on the page:
<?php /* Template Name: share template */ ?> <html> <?php get_header(); ?> <?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query('category_name=share'.'&paged='.$paged); ?> <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <?php endwhile; ?> <?php get_footer(); ?>
FYI, CaptainSEO, your posts are being caught as spam by Akismet. I keep cleaning them out of the queue, but it’ll be a while before it learns :/ That means there’s a weird delay in your posts showing up for everyone else until that happens, alas. Wish I knew why it got that way…
I also notice that I am shown as anonymous instead of my username.
Yeah, that happens when we haven’t un-spammed your reply quite yet *sigh*
I am using a plug-in for now, but any further help will be appreciated.
Ok so starting at line 87:
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
That’s called “the loop”. It’s looking to see if there are any posts, and if so loop through each one and display it. So you’d replace that bit with the code I showed you. It’s starts with the “if (have_posts)” part, but I don’t actually see where it ends that if statement…let us know if, after you replace the code, it throws an error. Something like “unexpected endif”.
I’ll see if I can modify the pastebin code for you…
Oh and you don’t need that <html> tag towards the top of your page template. The get_header call should pull in your header.php file which should already have that.
- The topic ‘Need to make a page display posts…’ is closed to new replies.