Jun
2007
15

Hiding Pages with Wordpress part 2 - Errors, Omissions, and Solutions

by Matt

In a previous post, how to hide pages in wordpress, I talked about hiding pages in wordpress. I gave three solutions, one was wrong Embarassed and the others were a little confusing. I could have sworn that the draft and private methods worked...maybe they were bugs in older versions? I want to thank a reader from blogsandbucks.com for pointing out that the draft method for hiding pages does not work.

if you make a page, and save it as a draft, you will be able to access it but only if you are logged in. I guess made a page and didn't logout to see how the write would look from.

adding exclude='' and include='' should still work, even for WP2.2...I'm looking into it.

exclude (string)
Define a comma-separated list of Page IDs to be excluded from the list (example: 'exclude=3,7,31'). There is no default value. See the Exclude Pages from List example below.
include (string)
Only include certain Pages in the list generated by wp_list_pages. Like exclude, this parameter takes a comma-separated list of Page IDs. There is no default value.
Source: wp_list_pages function at wordpress.org 

 I also want to thank, blogsandbucks for pointing me to the code section in the post-template.php file. Since a lot of people are having trouble with hiding pages from the menu and sidebars, I wrote a little script which adds checkboxes next to the pages in the admin section so you can easily hide pages.
hide pages from wordpress in the admin section

Warning, this is geeky...you will be editing 3 files...if you are scared, shoot me an email and I'll take care of you.

You can download the altered pages here: hide_pages.zip - for wp 2.2 only...but it might work with earlier versions.

first, we have to update the blog options to store an array of our hidden pages.

open wp-admin/admin-functions.php
You have to add the checkboxes to the table.

There is a function around line 830: page_rows( $parent = 0, $level = 0, $pages = 0, $hierarchy = true )
this function lists the pages in the admin section. You need to add a table row.

add this to the '<tr>' block...you should make it the last '<td>' section

CODE:
  1. <?php $hidden_pages = get_option('hidden_pages'); ?>
  2. <td align="center"><?php echo (in_array($id, (array)$hidden_pages)) ? "<input name='page_hide[]' type='checkbox' value=$id  checked='checked' />" : "<input name='page_hide[]' type='checkbox' value=$id  />" ; ?></td>

That code will add checkboxes to your admin pages section. you are done with this file. Save and upload to your website.

now open wp-admin/edit-pages.php
You have to wrap the table that lists the pages in a form. so you are going to add form tags around line 34.

CODE:
  1. <!--add these form tags-->
  2. <form action="" method="post">
  3. <table class="widefat">
  4.   <thead>
  5.   <tr>
  6.     <th scope="col" style="text-align: center"><?php _e('ID') ?></th>
  7.     <th scope="col"><?php _e('Title') ?></th>
  8.     <th scope="col"><?php _e('Owner') ?></th>
  9.     <th scope="col"><?php _e('Updated') ?></th>
  10.     <th scope="col" colspan="3" style="text-align: center"><?php _e('Action'); ?></th>
  11.     <th scope="col" style="text-align: center"><?php _e('Hidden') ?></th>
  12.   </tr>
  13.   </thead>
  14.   <tbody id="the-list">
  15. <?php
  16. page_rows(0, 0, $posts, $all);
  17. ?>
  18.   </tbody>
  19. </table>
  20. <!--add the closing form tags-->
  21. <p class="submit"><input name="update_pages" type="submit" value="Update Visiblity" /></p>
  22. </form>

this will send an array of hidden pages as post data to get inserted into the blog options.

Then right after "require_once('admin-header.php');" on line 6 of the same page add this code:

CODE:
  1. if(isset($_POST['update_pages']))
  2. {
  3.     $hidden = $_POST['page_hide'];
  4.     update_option('hidden_pages', $hidden);
  5. }

That will do the insert. you might need to serialize the $hidden variable before you update_option. I think on newer versions of WP, update_option will serialize arrays for you. 

you are done with edit-pages.php. Save and upload to website

Now open wp-includes/post-template.php
This is the page that controls the layout visible by the public. you will find a function called wp_list_pages($args = '') around line 277. a few lines after that you will see all the arguments you can send that function, one of which is exclude=''. right after this line: $r = array_merge($defaults, $r);
add this code:

CODE:
  1. if(get_option('hidden_pages')!='')
  2.     {
  3.             $r['exclude'] = implode(",", get_option('hidden_pages'));
  4.     }

that just reads your blog options and then makes a string of page id's to exclude. 

this is licensed under the WOMC (worked on my computer), so if you have any questions feel free to shoot an email.

Tags:

Popularity: 35% [?]

Other posts you might be interested in
  • How to hide Pages in wordpress  You might run across a time in your life when you need to hide a page in wordpress.You have 3
  • Better SEO for your Website using Plugins and Tags -Part 2  Ok, so we have our tags set up from part 1 for single post pages. Now we need to make
  • Blogsites Focusing on the Community with Diverse Solutions IDX MLS Search  We've been working on a few new community blogsites with lots of moving parts. Using Wordpress to build real
  • Answers to a few common questions About wordpress  The Wordpress questions are starting to roll in. The first couple questions come from Stacey Macioszek stateofmindrealestate.com Q.
  • How to Create Full PDF Web Pages that Require no Downloading  We've been asked recently about how to add property disclosure documents and floor plans to blogs and websites. There


  • Mar
    2007
    3

    Quick bug alert all our plugins…Fixed soon

    by Matt

    Dustin Sparks has brought a bug to my attention in the featured listings plugin for wordpress. This plugin requires a function called simple_xml() which allows a very easy way to share data, but it only works in PHP 5.

    PHP 5 is still in infancy, and only installed 14% of all servers running PHP.

    Chart compliments of: nexen.net

    I do have a fix, and I will have this patched soon.

    So if you run into a simple_xml function error with the featured listings plugin, agent details plugin, buyer and seller reports plugin...don't fret, it will soon be fixed and uploaded to realiventblog.

    Thanks
    Dustin

    Tags:

    Popularity: 7% [?]

    Other posts you might be interested in
  • Bug Alert - New SFARMLS Public Home Search  If you are a San Francisco Realtor an use the public home search tool for your websites, there is a little
  • Featured Listing Plugin - video tutorial  Here is a quick video showing how easy it is to add featured listings to your wordrpess blog: View the video It
  • PROPERTY BLOGSITES and FEATURED LISTINGS Widget - QUICK LINKS NAV BAR UPDATE  "Hello World!" Whoa, been doing too many Wordpress installs...We've been quite busy working on new features, new installations, and
  • Blogsites Focusing on the Community with Diverse Solutions IDX MLS Search  We've been working on a few new community blogsites with lots of moving parts. Using Wordpress to build real
  • New Themes for Propblogs  We've just added a bunch of new real estate related Propblogs themes.  If you have any real estate themes you want


  • Close
    E-mail It
    Rodney's Adsense-Deluxe Add ons plugged in.