Support » Fixing WordPress » Showing current page/category posts in sidebar

  • Hi there,
    I’m using WordPress as a CMS for my website, which combines static and dynamic content. I have set up two-tiered page/subpage-based navigation.
    I have two main page templates, page-posts.php and page-static.php, which I will use to display the bulk of the site’s content (there will be a couple of ‘special’ pages also, for example the Home page, each of which will have its own unique template).
    I’m currently working on the dynamic part of the site, ie. with pages which use the page-posts.php template. Each page displays posts from one category only (the name of each category matches the title of the page on which posts from that category are to be displayed). I am using the following code in page-posts.php to display posts from the relevant category in each page, and it seems to work okay:

    [code moderated per forum guidelines – please use the pastebin for any code over 10 lines]

    I’m having serious problems with my sidebar though, and haven’t been able to find a specific solution on the forums. I’m calling sidebar.php in the page-posts.php template, and I want it to display the titles of posts from the category that is displayed on each page, ie. the category whose name matches the current page’s title, up to a specified maximum number of titles
    Also, if there are less than 3 posts in this category, I would like to display 3 post titles randomly selected from 3 other specified, related post categories in addition to the ‘current’ category post titles (but I haven’t even attempted this part yet!)

    I’ve been going around in circles for the past few days trying to get it to work, but I’m not familiar enough with php to figure it out. I suspect I don’t have the right code in the sidebar to extract the title of the current page. The latest (non-functioning) code I have tried in sidebar.php is:

    [code moderated per forum guidelines – please use the pastebin for any code over 10 lines]

    I’d be extremely grateful for any advise anyone could give me – I’m completely stuck with this!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Showing current page/category posts in sidebar’ is closed to new replies.