0

I have created a custom post type called articles that will display an article each month. This custom post is hierarchical (which means it will also have children posts related to that monthly article).

My settings are these:

<?php
/* CUSTOM POST: MONTHLY ARTICLES */
add_action('init','create_monthly_articles');
function create_monthly_articles() {
    $labels = array(
        'name' => __('Articles','mgr'),
        'singular_name' => __('article','mgr'),
        'add_new' => _x( 'Add new article', '${4:Name}', 'mgr' ),
        'add_new_item'       => __( 'Add new article', 'mgr' ),
        'edit_item'          => __( 'Edit article', 'mgr' ),
        'new_item'           => __( 'New article', 'mgr' ),
        'view_item'          => __( 'View articles', 'mgr' ),
        'search_items'       => __( 'Search articles', 'mgr' ),
        'not_found'          => __( 'No articles found', 'mgr' ),
        'not_found_in_trash' => __( 'No articles found in Trash', 'mgr' ),
        'parent_item_colon'  => __( 'Parent article name:', 'mgr' ),
        'menu_name'          => __( 'Articles', 'mgr' ),        
    );

    $args = array(
        'labels' => $labels,
        'hierarchical' => true,
        'description' => __('A monthly article','mgr'),
        'taxonomies' => array('category'),
        'public' => 'true',
        'show_ui'             => true,
        'show_in_menu'        => true,
        'menu_position'       => 5,
        'show_in_nav_menus'   => true,
        'publicly_queryable'  => true,
        'exclude_from_search' => false,
        'has_archive'         => true,
        'query_var'           => true,
        'can_export'          => true,
        'rewrite' => array(
            'with_front' => false,
            'slug'       => 'articles'
        ),
        'capability_type'     => 'post', 
        'supports'            => array( 
            'title', 'editor', 'author', 'thumbnail', 
            'custom-fields', 'trackbacks', 
            'revisions', 'page-attributes',
        ),
    );

    register_post_type('cpt_article',$args);
}

What I want to do is, that when I call http://myblog.com/articles/ would show me the last monthly article published, which is a single-cpt_article.php. Inside that page I have attached a link for the custom post type archive, which will show all the articles sorted by month.

Without archive.php / archive-cpt_article.php I can see the article page as I customized when I hit http://myblog.com/articles/myarticle but when I click archive it gets me to /articles/ where there is a generic category.php page that I need for the rest of the project. How can I have an intro (homepage) that shows the latest article for that specific cpt and an archive page for all the entries in that specific cpt?

The navigation I am trying to achieve is like this:

HOME -> ARTICLES -> SUB ARTICLES (Related to monthly article)
                 -> ARCHIVE PAGE (All top level articles sorted by month)
0

I think you are searching for custom page-template.

Make yourself a page-customarchive.php and name her in the top of the file.:

    <?php
    /*
    Template Name: customarchive
    */

//Your custom query for this post_type

Put her in your theme directory

Then make a new Page in Wordpress and pick from the right side the template you just made.

Now get the Permalink of this Page and put it in your "single-cpt_article.php", where you want to provide the link.

  • Actually I achieved this as follows: From the home page menu, I entered the category of the custom post (in the menu as entry it was category/monthly ). The menu permalink, links to the custom post article (single-cpt_article.php) because category-monthly.php is a redirect to the first published article. /articles leads to the archive. Now I can't seem to load the specific article if I am using a date, I've seen some implementations but they were all before wordpress's one. What I mean is that now I get the monthly archives, but when I click that it leads me to a non cpt page. – Panagiotis Sep 16 '14 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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