• I made a theme option called exclude_page for excluding pages in my blog and I’m using it like this..

    <?php wp_list_pages('exlude='.$exclude_page = get_option('exclude_page') .'&title_li='); ?>

    but instead of placing that code in the header, sidebar, and anywhere where I’m listing pages, is it possible to call a function that will exclude the ID everywhere on the blog?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Sounds a bit odd, but since functions.php is referenced by everything in WP (as I understand it) why not put something like $output = wp_list_pages('exlude='.$exclude_page = get_option('exclude_page') .'&title_li='); in there.

    Not quite sure how you’d use it, though, or if you’re trying to save time updating it? Seems more trouble than it’s worth.

    Thread Starter nemci7v

    (@nemci7v)

    Thanks for the code! I added it but I get the page list on all my pages, on top before the header, even in the dashboard. Maybe I added it wrong? I pasted it after the register sidebars functions.

    I’m trying to do this to shorten the codes in my theme. I have a page list in the header, sidebar, and some in other page templates. I though it would be easier to have a global function instead of adding the option to all the wp_list_pages tags.

    No, it won’t be easier!

    No!

    Not being rude, but I thought you knew what you were doing. IF you really want to go that way, just use an include. But it’ll slow your site down marginally. It’s really, really not worth the trouble. 🙂

    Thread Starter nemci7v

    (@nemci7v)

    It’s ok 🙂 I’m trying to learn.

    So bottom line it’s better to simply add

    exlude='.$exclude_page = get_option('exclude_page')

    to wherever I’m listing pages? I still don’t understand why a global function won’t be easier. Are you referring to easy coding wise? To me, adding 1 function that alters all the page lists seems more time efficient instead of calling the option several times in page templates. I don’t mean to disagree with you, you obviously have more experience but I’m trying to understand why.

    wp_list_pages(‘exlude=’.$exclude_page = get_option(‘exclude_page’) .’&title_li=’);

    your code is good. but you forgot to put parameter : “echo=0”, show the result can be save into a variable.

    so, Put this on your function.php

    $GLOBALS[‘mynonexludepage’] = wp_list_pages(‘echo=0&exlude=’.$exclude_page = get_option(‘exclude_page’) .’&title_li=’);

    then put this on anywhere you want

    print_r( $GLOBALS[‘mynonexludepage’]);
    unset ($GLOBALS[‘mynonexludepage’]);

    Thread Starter nemci7v

    (@nemci7v)

    Thanks for the code uwiuw! I integrated it without any problems and the page list appears when I use

    print_r( $GLOBALS['mynonexludepage']);
    unset ($GLOBALS['mynonexludepage']);

    ,,in my template but it doesn’t register the excluded page IDs. It’s an interesting function but I think I’ll wait to learn some more php and really understand it..

    You mentioned that I forgot the echo=0. Without the global function code would it make sense for me to add echo like this?

    wp_list_pages('echo=1&exlude='.$exclude_page = get_option('exclude_page') .'&title_li=');

    It works without the echo but I’m not sure if it provides an advantage. Thanks!!

    the echo parameter will store the pages into variabel, rather then display it. 😉

    echo
    (boolean) Toggles the display of the generated list of links or return the list as an HTML text string to be used in PHP. The default value is 1 (display the generated list items). Valid values:

    * 1 (True) – default
    * 0 (False)

    taken from wp_list_pages

    Thread Starter nemci7v

    (@nemci7v)

    Thanks for sharing! I guess I’ll keep the echo then 🙂

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Excluding page globally’ is closed to new replies.