¿Puedo establecer algunas páginas predeterminadas que se creará en cada creación de un nuevo blog

wordpress.stackexchange https://wordpress.stackexchange.com/questions/1030

  •  16-10-2019
  •  | 
  •  

Pregunta

Las páginas como "aproximadamente" se creará automáticamente cuando se crea un nuevo blog. Del mismo modo que necesito algunas otras páginas que deben aparecer automáticamente cuando se crea un blog bajo mis multi-sitio.

¿Cómo puedo configurar las páginas predeterminadas que se crean con un nuevo blog bajo un multisitio?

Por ej .: Si tengo un multisitio en example.com. Cada blog creado en virtud de este sitio debe tener Inicio, Acerca de, Mi tienda, Mi dirección.

¿Fue útil?

Solución

I recommend creating a function in your functions.php file that ties to the action hook activate_blog. Use the WordPress functions get_pages() to see if your default pages exist. If they do not, create them with wp_insert_post.

add_action('activate_blog','my_default_pages');

function my_default_pages(){
    $default_pages = array('About','Home','My Store','My Address');
    $existing_pages = get_pages();

    foreach($existing_pages as $page){
        $temp[] = $page->post_title;
        }


    $pages_to_create = array_diff($default_pages,$temp);

    foreach($pages_to_create as $new_page_title){

            // Create post object
            $my_post = array();
            $my_post['post_title'] = $new_page_title;
            $my_post['post_content'] = 'This is my '.$new_page_title.' page.';
            $my_post['post_status'] = 'publish';
            $my_post['post_type'] = 'page';



            // Insert the post into the database
            $result = wp_insert_post( $my_post );

        }
        }

To test this function on your own site, try setting the hook to wp_head. It will run on each page load and insert the pages that don't exist, with the content in $my_post['post_content']. *Does the 'activate_blog' hook run when blogs are created in a multi-site context? I don't know.*

Refer to the codex page for wp_insert_post that I linked to for the complete list of default parameters available.

Otros consejos

use "wpmu_activate_blog" instead of "activate_blog". it worked for me. thanks

Licenciado bajo: CC-BY-SA con atribución
scroll top