Forums

[closed] Linking to Pages (9 posts)

  1. alexduff
    Member
    Posted 1 year ago #

    Would really appreciate help with the following:

    I'm trying to create a theme for school pupils to use => don't want them to have to change anything - select the theme, and everything works.

    This is going OK: I've edited K2 to a level where I'm almost happy with it.

    HOWEVER...

    I've created one overview page, and a number of subject specific pages [Maths, English,...]. The idea is that from the overview page, the pupil can click on a subject-specific page to edit that page and add in comments for that subject. The teacher can then post comments back to the pupil on that page.

    I am finding it impossible to link from the overview page to the subject-specific pages. I am adding the pages in functions.php and using this to add the contents in HTML; however, this method does not appear to allow php to be added therefore I cannot see how I can dynamically reference the new pages.

    The subject-specific pages have been excluded as they'd cluter up the screen otherwise.

    Is it possible to program in that slugs get used in URL's, or is there some other method I could use?

    Any help/suggestions/ideas would be most greatly appreciated.

  2. duck__boy
    Member
    Posted 1 year ago #

    Is the overview page static for the most part? If so, I'd just use static links - Page Name

  3. alexduff
    Member
    Posted 1 year ago #

    Thanks, duck__boy.

    The problem with that though is that the pages are set to have an ID, eg page_id=14

    These IDs of course could vary from one install to another; therefore I cannot simply use a link such as that.

    I'd love to use a static link using the slug, but don't know if it's possible to code in a change from using IDs to slugs for the URLs - is that what you're hinting at, and if so, do you know how that could be done?

  4. converting2wp
    Member
    Posted 1 year ago #

    Can you give a reference to what you mean by "adding the pages in functions.php"?

    It sounds as if the maths, etc., pages are not created using the backend "new page" and so whatever permalink structure you're using there doesn't apply?

  5. alexduff
    Member
    Posted 1 year ago #

    You are correct, conv - I've not used the backend to create the pages. They're created on the fly when the theme gets selected. This is how I've created the pages inside functions.php:

    [Code moderated as per the Forum Rules. Please use the pastebin]

  6. converting2wp
    Member
    Posted 1 year ago #

    Once they are created, do you see them in the Pages panel in the dashboard? If you try to edit them there, does anything show up in the permalink line? And those permalinks work?

    I'm guessing the problem is that you want to generate the list of links on the home page from the same array that you used to build the series of "add_page" lines in your functions.php. [I sometimes use a localize.php file for data like that when I'm building a set of similar sites.]

    To put that onto your home page, you can use a plugin that allows PHP on WordPress Pages, or use a custom template for the home page.

    Do either of those sound like ideas that might help -- or am I missing the point entirely?

  7. converting2wp
    Member
    Posted 1 year ago #

    And if the question of slugs and "pretty" permalinks doesn't work, all I can think of is that you recode the add_page to return the IDs of the new pages and store those somewhere that they can be accessed. [But you'll still need to get the PHP onto the page.]

  8. alexduff
    Member
    Posted 1 year ago #

    Thanks, Conv.

    Yes - they do appear in the dashboard, and I could edit them there; however, I really don't want to do that - the theme is for pupils, and I want a solution out of the box with zero customisations required from them.

    I think what I might do is create a second version of sidebar.php and create a new template refering to the new sidebar. This new version would contain the links to the pages. This might work.

    Thanks for your suggestions - very much appreciated.

    If I get this working, I'll post the solution up here; of course in the interim if anyone else has any other suggestions, I'm all ears!! :)

  9. alexduff
    Member
    Posted 1 year ago #

    The solution was far easier than I ever expected!!! Even with the code

    [Code moderated as per the Forum Rules. Please use the pastebin]

    which does what I was after, the excluded pages appear as links in the sidebar abovr the Pages links as Subpages links - real bonus!!

Topic Closed

This topic has been closed to new replies.

About this Topic