SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard silver trophy TheOriginalH's Avatar
    Join Date
    Aug 2000
    Location
    Thailand
    Posts
    4,811
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Categories and pages, can they play together?

    I have solved the sidebar issue, but have another.

    I have a page on a clients site that I would like them to be able to edit as normal for a Wordpress page. However I'd also like to be able to pull blog posts from a certain category and allow them to be displayed after the content of the page. Can anyone give me some pointers?
    ~The Artist Latterly Known as Crazy Hamster~
    922ee590a26bd62eb9b33cf2877a00df
    Currently delving into Django, GIT & CentOS

  2. #2
    SitePoint Enthusiast jaredwilli's Avatar
    Join Date
    Apr 2010
    Location
    Boston, Ma.
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Simple, you just need to create a new custom loop. Or more specifically, a custom page template. Here's a tutorial I posted for more information on this if needed. And another tutorial I wrote for creating custom loops.

    To create a template, you can just make a copy of your page.php file, rename it page-your_special_page.php, (make sure that when creating the page for this in the dashboard that the page slug matches your_special_page).

    Then all you would need to do in the file is create a custom loop after the normal one.

    For example, here's a loop you may have for showing your page content

    PHP Code:
    if (have_posts()) :
    while (
    have_posts()) : the_post();

      
    // show your page stuff, title, page text etc.

    endwhile;
    endif; 
    After this part, you could add something like this:

    PHP Code:
    $custom = new WP_query();
    $custom->query('post_type=post&post_status=publish&posts_per_page=5&cat=CATEGORY_ID" );
    if (have_posts()) : 
        while ($custom->have_posts()) : $custom->the_post();
            ?>
                  // show your posts as a custom list or whatever here

             <?php
             
    endwhile;
    endif;

    posts_per_page=5 - number of posts your want to retrieve

    cat=CATEGORY_ID - the ID # of the category you want posts from
    OR use this instead:
    cat_name=category_name - the name of your category, case sensitive

    Hope this helps!

  3. #3
    SitePoint Wizard silver trophy TheOriginalH's Avatar
    Join Date
    Aug 2000
    Location
    Thailand
    Posts
    4,811
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Nice one, thank you Jared
    ~The Artist Latterly Known as Crazy Hamster~
    922ee590a26bd62eb9b33cf2877a00df
    Currently delving into Django, GIT & CentOS


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •