Use page template instead of custom post type archive

admin2025-01-08  3

I'm using a plugin that creates a projects custom post type called wm_projects.

I configured my archive-wm_projects.php template to show the overview on /projects/ and my single page template, single-wm_projects.php, on URL /projects/1st-project/.

Now I want to use a WordPress page that loads the archive-wm_projects.php template because I want to use the URL structure and the page title (currently this is projects archive), I also want to upload an image there for my header.

Also, I'm using the Yoast SEO plugin.

I've Been looking for an answer that fits my needs, but doesn't look like anyone else wants to configure the site in this way.

[EDIT1]

Let me try to explain it a bit more. I'm using a childtheme, those files are listed in my childtheme

Projects archive
The page i want the projects to been showing, this is using the page-template-archive-wm_projects.php template

page-template-archive-wm_projects.php

<?php 
/**
 * Template Name: Project Archives
 */

require( locate_template( 'archive-wm_projects.php' ) );

exit();

archive-wm_projects.php

<?php get_header(); ?>

<?php // START if have posts ?>
<?php if ( have_posts() ) : ?>
    <div id="wrap">
        <div id="content" role="main">
            <div class="container">
                <div class="row">
                    <?php while ( have_posts() ) : the_post(); ?>
                        <?php
                            get_template_part( 'portfolio_overview' );
                        ?>
                    <?php endwhile; ?>
                </div>
            </div>
        </div>
    </div>
<?php endif; ?>
<?php get_footer(); ?>

portfolio_overview.php

<div class="col-sm-4">
    <div class="project-header">
        <?php $pageHeader = get_field('project_header'); ?>
        <img src="<?php echo $pageHeader['url']; ?>" alt="<?php echo $pageHeader['alt']; ?>" />
    </div>
    <header>
        <?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
    </header>
    <div class="readMore">
        <a href="<?php get_permalink() ?>">Lees verder</a>
    </div>
</div>

I'm using a plugin that creates a projects custom post type called wm_projects.

I configured my archive-wm_projects.php template to show the overview on /projects/ and my single page template, single-wm_projects.php, on URL /projects/1st-project/.

Now I want to use a WordPress page that loads the archive-wm_projects.php template because I want to use the URL structure and the page title (currently this is projects archive), I also want to upload an image there for my header.

Also, I'm using the Yoast SEO plugin.

I've Been looking for an answer that fits my needs, but doesn't look like anyone else wants to configure the site in this way.

[EDIT1]

Let me try to explain it a bit more. I'm using a childtheme, those files are listed in my childtheme

Projects archive
The page i want the projects to been showing, this is using the page-template-archive-wm_projects.php template

page-template-archive-wm_projects.php

<?php 
/**
 * Template Name: Project Archives
 */

require( locate_template( 'archive-wm_projects.php' ) );

exit();

archive-wm_projects.php

<?php get_header(); ?>

<?php // START if have posts ?>
<?php if ( have_posts() ) : ?>
    <div id="wrap">
        <div id="content" role="main">
            <div class="container">
                <div class="row">
                    <?php while ( have_posts() ) : the_post(); ?>
                        <?php
                            get_template_part( 'portfolio_overview' );
                        ?>
                    <?php endwhile; ?>
                </div>
            </div>
        </div>
    </div>
<?php endif; ?>
<?php get_footer(); ?>

portfolio_overview.php

<div class="col-sm-4">
    <div class="project-header">
        <?php $pageHeader = get_field('project_header'); ?>
        <img src="<?php echo $pageHeader['url']; ?>" alt="<?php echo $pageHeader['alt']; ?>" />
    </div>
    <header>
        <?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
    </header>
    <div class="readMore">
        <a href="<?php get_permalink() ?>">Lees verder</a>
    </div>
</div>
Share Improve this question edited Nov 9, 2016 at 20:05 user2860384 asked Nov 8, 2016 at 19:17 user2860384user2860384 135 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You can create a page template named template-page-projects-archive.php (for example) that contains the following code:

<?php 
/**
 * Template Name: Project Archives
 */

require( locate_template( 'archive-wm_projects.php' ) );

exit();

When editing a page where you'd like to use the archive-wm_projects.php template, just select Project Archives from the template dropdown.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736270660a1445.html

最新回复(0)