Support » Fixing WordPress » how do I create a page http://sitename/post/

  • Hello,

    I developing a new theme and I’ve been testing it in a developing site with posts and three additional special custom post types.

    In this new theme, I’m using index.php for displaying all the items in the website (the posts and all of custom post types entries) adding a new function in filter pre_get_post and I use the same criteria in searches, category pages and author’s page entries displays.

    if ( ( $query->is_main_query() ) && ( is_home() || is_category() || is_search() || is_author() ) ) {
    $query->set( 'post_type', array( 'post', 'proyecto', 'publicacion', 'obra' ) ); }

    so, http://www.sitename.com -> the list of all class of entries

    I define the three custom post types with a permalink URL structure through ‘rewrite’ parameter in register_post_type() function.

    'rewrite' => array("slug" => $post_type_name, 'with_front' => false )

    so for displaying the list of any custom_post_type entries simply introducing a URL like http://www.sitemane.com/post_type1/ wordpress accesses to archive-post_type1.php.

    so, http://www.sitename.com/post_type_name/ -> for any of custom_post_type

    Well, I’d like to do the same with posts. I would like to use a URL like http://www.sitename.com/post/ for accessing directly to archive.php or even better archive-post.php and display the list of posts. It’s possible?

    I’d like…
    http://www.sitename.com/post/ -> for a list of the posts

    I know that it is possible to do something similar defining a ‘page’ in the first option of the admin menu settings > read, but I don’t like this solution… And I wonder if it exists another better and more direct solution. Perhaps something like to redefine the ‘rewrite’ parameter in the definition of Post Type ‘post’ or something via rewrite rules, etc…

    Thanks in advance.

    Joan Miquel

Viewing 1 replies (of 1 total)
  • Thread Starter jmviade

    (@jmviade)

    Finally I discover how to redirect posts to an archive.php

    function add_post_archive_page() {
    global $wp_post_types;
    $wp_post_types['post']->has_archive = true;
    $wp_post_types['post']->rewrite = array( 'slug' => 'entrada' , 'with_front' => false, 'feed'=> true, 'pages' => true );
    add_rewrite_rule('^entrada/page/([0-9]{1,})/?', 'index.php?post_type=post&paged=$matches[1]', 'top');
    add_rewrite_rule('^entrada/(feed|rdf|rss|rss2|atom)/?','index.php?post_type=post&feed=$matches[1]','top');
    add_rewrite_rule('^entrada/feed/(feed|rdf|rss|rss2|atom)/?','index.php?post_type=post&feed=$matches[1]','top');
    add_rewrite_rule('^entrada/?','index.php?post_type=post','top');
    flush_rewrite_rules();
    }
    add_action( 'init', 'add_post_archive_page' );

    I hope to this function helps you.

    Joan Miquel

Viewing 1 replies (of 1 total)
  • The topic ‘how do I create a page http://sitename/post/’ is closed to new replies.