• Please help!

    I am designing a site that is a mixture of pages and posts (mostly news items and factsheets). What I would like to do is to have a list of related posts in the sidebar on relevant pages.

    eg: on the community law pages, I would like the community law factsheets and community law news items to be listed in the sidebar. On the employment law pages, I would like the employment law post items to be listed in the sidebar.

    I can do this with NAVT lists, but I really want to avoid using javascript if at all possible. So I need code that will do the following:


    If the page parent/page grandparent ID of this page is (community law) then list the posts that exist under the following (community law) categories.

    elseif the page parent/page grandparent ID of this page is (employment law) then list the posts that exist under the following (employment law) categories.

    and so on to endif.

    I am nearly there with the logic, but I just can’t get there with the code…If someone can give me the php code for that, I will buy them a virtual drink of their choice. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter juliageek

    (@juliageek)

    Ok I did it and here’s how:

    <ul>  <?php
    
    if
    (is_page(101) || $post->post_parent=="101")//this is employment law pages
    {
    wp_list_categories('orderby=name&use_desc_for_title=0&child_of=157&title_li=<h2>Also on this Site:</h2>'); //list the employment law resources
    }
    elseif
    (is_page(57) || $post->post_parent=="7")//this is community care law pages
    {
    wp_list_categories('orderby=name&use_desc_for_title=0&child_of=155&title_li=<h2>Also on this Site:</h2>'); //list the community care law resources
    }
    elseif
    (is_page(218) || $post->post_parent=="218")//this is housing law pages
    {
    wp_list_categories('orderby=name&use_desc_for_title=0&child_of=156&title_li=<h2>Also on this Site:</h2>'); //list the housing law resources
    }
    else {
    	echo ('');
    	}
    ?>
    </ul>

    All I’ve got to do now is make it work for grandchildren of the parent pages, and not to work if there are no categories….

    Thanks for that! only I am not really sure where to integrate the code, could you tell me how I should make this work? thanks again!

    Thread Starter juliageek

    (@juliageek)

    Hi

    Sorry it took so long to get back – I don’t usually get questions on my posts. It feels like I’ve sort of graduated!

    I put this in the sidebar.php file of the theme I was using (found in wp-content/themes/yourtheme/. If you’ve not messed around at that level before, do make a backup of the original file first – I learnt the hard way!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘How do I list posts in certain categories on related pages?’ is closed to new replies.