Forums

Quick php question: exclude pages from sidebar list (8 posts)

  1. Hardhat
    Member
    Posted 3 years ago #

    Hi all

    As my php coding skills are still newbie-ish...

    I want to exclude 2 pages from my sidebar list in a particular template. Their ID's are 56 & 57

    My current template code includes the following PHP:

    <?php if (is_page()) { $highlight = "page_item"; } else {$highlight = "page_item current_page_item"; } ?>
    <?php wp_list_pages('sort_column=menu_order&depth=1&title_li='); ?>

    Any PHP'er can point out to me what to adjust / add in order to achieve this for this template?

    As always, all help appreciated!

    Kind regards

    Hardhat :)

  2. Roy
    Member
    Posted 3 years ago #

    I'm sure you read the Codex for this sort of questions?
    It's very helpfull sometimes :-)

  3. Hardhat
    Member
    Posted 3 years ago #

    Hi G

    I read it, but am having difficulty trying to figure out exactly where to put the 'exclude'.

    Told you I was a newbie.

    Can any kind soul just give me some code on this?

    H

  4. Roy
    Member
    Posted 3 years ago #

    That's the code you can use in your sidebar.php (it says: "list, except these few"), but my guess is that you use widgets? In that case it might be easier to look for a plugin to do the trick for you.

  5. Hardhat
    Member
    Posted 3 years ago #

    Hi G

    Sorry to contradict, but, no, I don't use widgets.

    I've got the whole "list except these few" thing but, as I'm not a PHP-happy coder, I don't know how to incorporate that request into my existing template without destroying the existing functionality.

    Again, at the risk of seeming a little pushy, I'm just hoping for someone who's PHP-savvy to just show me the adjusted code - amended from the block I supplied - to incorporate back into my template.

    Again, all help appreciated.

    H

  6. Roy
    Member
    Posted 3 years ago #

    I'm not either, but you can only learn by trying. My first guess would be:

    <?php wp_list_pages('exclude=17,38 sort_column=menu_order&depth=1&title_li='); ?>

  7. moshu
    Member
    Posted 3 years ago #

    No PHP required. Just excellent reading and Copy/Paste skills. So go back to the Codex article and read it again. And again...

  8. Hardhat
    Member
    Posted 3 years ago #

    OK chums

    I get the whole 'learn by digging' thing too, but, considering this is my day off I guess maybe I was being somewhat lazy... :)

    Alright, as a non-PHP savvy guy let me try this one on you:

    As I'm using a hacked-about version of an Andreas Wiklund template, I have another string of PHP in my page template (as opposed to theheader template code I mentioned at the start of this post).

    The code runs:

    <?php list_subpages_andreas01(); ?> <?php // This generates the subpage menu. If you don't want to use it, delete this line. ?>

    Now, Was I on the right track with the original code block, or is this the block that requires adjustment?

    Please note: (if it makes any difference) that it is my right-hand sub-page menu, as opposed to my left-hand main menu that I'm trying to exclude certain pages from

    H

Topic Closed

This topic has been closed to new replies.

About this Topic