0

I having and issue with my permalinks, I wonder if someone has solved this.

Basically I have a page named videos and also a post-type name videos, so I try to access to /videos I doesnt not display the right content.

Any change I can keep videos as my page slug and also keep videos/video-post-types-links as well???

Thanks in advanced.

2
  • You have a clash
    – Tom J Nowell
    May 14, 2014 at 23:04
  • what does your post type registration code look like?
    – Milo
    May 15, 2014 at 0:00

1 Answer 1

1

You can created a post template to display the CPT post details (i.e. videos/my-video) and you can create an archive template to display a list of posts (i.e. videos/).

To create a post template in a plugin, add the following to the plugin:

function include_templates( $template_path )
{
    if ( get_post_type() == 'videos' )
    {
        if ( is_single() )
        {
            // checks if the file exists in the theme first,
            // otherwise serve the file from the plugin
            if ( $theme_file = locate_template( array( 'single-videos.php' ) ) )
            {
                $template_path = $theme_file;
            }
            else
            {
                $template_path = plugin_dir_path( __FILE__ ) . 'single-videos.php';
            }
        }
    }
    return $template_path;
}

add_filter( 'template_include', 'include_templates', 1 );

Then create a template called single-videos.php in the plugin folder:

<?php get_header(); ?>
<?php while(have_posts()) : the_post(); ?>

        <h1><?php the_title(); ?></h1>
        <?php the_content(); ?>

<?php endwhile; ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

To create a archive template in a plugin, add the following to the plugin:

function include_archive_template($archive_template)
{
     global $post;

     if ( is_post_type_archive ('videos') )
     {
          $archive_template = plugin_dir_path( __FILE__ ) . 'archive-videos.php';
     }
     return $archive_template;
}

add_filter( 'archive_template', 'include_archive_template' );

Then create the archive-video.php file on the plugin folder:

<?php get_header();

    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    $big = 999999999; // need an unlikely integer

    // Get Video details
    $args = array(
        'post_type' => 'vdieos',
        'order' => 'ASC',
        'orderby' => 'title',
        'posts_per_page' => 10,
        'paged' => $paged
    );
    $wp_query = new WP_Query($args);

    $page_args = array(
        'base'         => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'format'       => '?paged=%#%',
        'total'        => $wp_query->max_num_pages,
        'current'      => $paged,
        'show_all'     => False,
        'end_size'     => 1,
        'mid_size'     => 2,
        'prev_next'    => True,
        'prev_text'    => __('«'),
        'next_text'    => __('»'),
        'type'         => 'list',
        'add_args'     => False,
        'add_fragment' => ''
    );
    echo paginate_links( $page_args );

    while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

    <div class="video_row clearfix">
        <h3><a href="<?php echo get_permalink( $post->ID ); ?>"><?php the_title() ?></a></h3>
        <?php the_content(); ?>
        <a href="<?php echo get_permalink( $post->ID ); ?>">More Details</a>
    </div>

<?php
    endwhile;
    echo paginate_links( $page_args );
    wp_reset_postdata();

get_sidebar();
get_footer(); ?>
1
  • I don't see how this answers the question.
    – Milo
    May 15, 2014 at 18:19

Your Answer

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

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