0

i want to put an internal wordpress page (for example Contact page) to the admin panel, in order to dont have to go though Pages->All Pages, is it possible?

with the above code it seems that it can only retrieve some pages, not all of them. In many pages i get bool(false) and the template page is for sure correct. in one page i get this

object(WP_Post)#823 (28) { ["ID"]=> int(13) ["post_author"]=> string(1) "1" ["post_date"]=> string(19) "2013-11-06 09:31:01" ["post_date_gmt"]=> string(19) "2013-11-06 09:31:01" ["post_content"]=> string(0) "" ["post_title"]=> string(4) "Home" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "publish" ["comment_status"]=> string(4) "open" ["ping_status"]=> string(4) "open" ["post_password"]=> string(0) "" ["post_name"]=> string(4) "home" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2013-11-06 10:40:37" ["post_modified_gmt"]=> string(19) "2013-11-06 10:40:37" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(37) "http:// localhost/medetail/?page_id=13" ["menu_order"]=> int(0) ["post_type"]=> string(4) "page" ["post_mime_type"]=> string(0) "" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" ["meta_id"]=> string(2) "11" ["post_id"]=> string(2) "13" ["meta_key"]=> string(17) "_wp_page_template" ["meta_value"]=> string(13) "page-home.php" }

also i noticed in this one that the http:// localhost/medetail/?page_id=13 is not correct

1 Answer 1

0

Yes, it's possible.

First of all you need a way to identify the page. there are different way to do it: by page slug, by page template...

I suggest you to create a fucntion that retrieve that page.

Let's assume the contact page has a page template called 'page-contacts.php'.

function get_contact_page() {
  $args = array(
    'number' => 1,
    'meta_key' => '_wp_page_template',
    'meta_value' => 'page-contacts.php'
  );
  $pages = get_pages($args);
  return ! empty( $pages ) ? array_pop($pages) : FALSE;
}

If you want to use a different way to identify your page, change this function accordingly.

After that, create a function to add the menu item hooking admin_menu:

function my_contact_page_menu() {
    $page = get_contact_page();
    if ( ! $page ) return;
    global $menu;
    $menu[] = array (
      'Contact Page', // menu label
      'manage_options', // capability
      get_edit_post_link( $page->ID, '' ),
      NULL,
      'menu-top menu-icon-post',
    );
}
add_action('admin_menu','my_contact_page_menu');
2
  • thank you very much for your answer! My template is page-contact.php , i changed your code and put it at the end of the functions.php of my theme but its not showing anything in the admin menu..
    – lucky13
    Nov 12, 2013 at 7:32
  • @Thanos be sure the page is retrieved by correctly. Try to insert var_dump($page); just after $page = get_contact_page();.
    – gmazzap
    Nov 12, 2013 at 7:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.