• Resolved death-dream

    (@death-dream)


    I am creating a page on my theme that will display many sections of new’s posts but I want each section to be put insides it’s own div basically:

    <div><?php get(‘cat1’); ?></div>

    <div><?php get(‘cat2’); ?></div>

    <div><?php get(‘cat3’); ?></div>

    It’s more on a design basis so just go with me on this. What is the php code to display every news post that is inside that category?

    Thanks =D

    ~Death Dream~

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter death-dream

    (@death-dream)

    Anyone? If this doesn’t make any sense let me know and I will try to clarify it.

    ~Death Dream~

    Here is one example, that should get you going. Change the div id, li class, your h2 title, YOURCATEGORY to match your category name you want to show, and showposts is how many you want to show. This basically just makes a list of the posts for a category. If you wanted to add the content to this page too, you should read more about the loop at http://codex.wordpress.org/The_Loop

    <div id="YOUR_DIV">
    <?php if (have_posts()) : ?>
    <h2>YOUR_TITLE</h2>
    <?php $temp_query = $wp_query; ?>
    <?php query_posts('category_name=YOURCATEGORY&showposts=10'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    <ul><li class="YOUR_LIST"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li></ul>
    </div>
    <?php endwhile; ?>
    <?php else : ?>
    <h2 class="center">Not Found</h2>
    <p class="center">Sorry, but you are looking for something that isn't here.
    
    <?php endif; ?>
    </div>
    Thread Starter death-dream

    (@death-dream)

    Alright sweet man! Thanks! I will check this code out and see what I can manage =D

    ~Death Dream~

    Thread Starter death-dream

    (@death-dream)

    <?php query_posts('category_name=YOURCATEGORY&showposts=10'); ?>

    What does the YOURCATEGORY depend on? I see several ways WordPress refers to a certain category.

    Would it be: “Category Name,” “Category Slug,” or would it be the Permalink? My Permalink is currently showing a number which I do plan on changing.

    ~Death Dream~

    Exact name of the category. It is case sensitive and can contain spaces.

    Thread Starter death-dream

    (@death-dream)

    Alright =D Wasn’t sure about the spaces thing. I’ll will start placing the code on my page and see what happens. Thanks for the fast response =D

    ~Death Dream~

    Thread Starter death-dream

    (@death-dream)

    Got everything working! Thanks for your wonderful help jbrndt!

    ~Death Dream~

    Thread Starter death-dream

    (@death-dream)

    Hey jbrndt, is there a way to make it obey the <!–more–> tag? It likes to post the whole page on there.

    ~Death Dream~

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘php code for one category’ is closed to new replies.