• I want my page /uploaded-documents/ to only show posts from the category “shared” and nothing else.

    How do I do that?

Viewing 15 replies - 1 through 15 (of 15 total)
  • 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(); ?>
    Thread Starter CaptainSEO

    (@captainseo)

    Aha – I see.

    Thanks. I’ll go away and try that right now.

    Thread Starter CaptainSEO

    (@captainseo)

    And where exactly does it go. I placed the code where I thought logical but it stops the page loading.

    [Large code excerpt removed by moderator per forum rules. Please use the pastebin for all large code excerpts. It works better anyway.]

    Thread Starter CaptainSEO

    (@captainseo)

    First I’ve heard of the pastebin. I’ll go do that and come back here with the link or whatever.

    Thread Starter CaptainSEO

    (@captainseo)

    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.

    Thread Starter CaptainSEO

    (@captainseo)

    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?

    Thread Starter CaptainSEO

    (@captainseo)

    Can you show me in the pastebin link? I would really appreciate it.

    Thread Starter CaptainSEO

    (@captainseo)

    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(); ?>
    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    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…

    Thread Starter CaptainSEO

    (@captainseo)

    I also notice that I am shown as anonymous instead of my username.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Yeah, that happens when we haven’t un-spammed your reply quite yet *sigh*

    Thread Starter CaptainSEO

    (@captainseo)

    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.

    Thread Starter CaptainSEO

    (@captainseo)

    Got it thanks – works a treat.

    Very much appreciated.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Need to make a page display posts…’ is closed to new replies.