wordpress make posts archive page code example

Example: wordpress change posts archive

add_action('init', 'post_slug_rewrite');

/* You can change "blog" to any slug you prefer.
   line 10 and 12.
*/
function post_slug_rewrite()
{
	$args = objectToArray( get_post_type_object('post') );

	$args['has_archive'] = 'blog';
	$args['rewrite'] = array(
			'slug' => 'blog',
			'with_front' => FALSE,
	);

	register_post_type('post', $args);
}

function objectToArray( $object )
{
	if( !is_object( $object ) && !is_array( $object ) )
	{
			return $object;
	}

	if( is_object( $object ) )
	{
			$object = get_object_vars( $object );
	}

	return array_map('objectToArray', $object);
}

Tags:

Php Example