0
votes

I am working on my Wordpress portfolio site and created a custom post type for my portfolio section. When a user clicks on my portfolio link it takes them to archive-portfolio.php which displays a gallery of all my projects and when they click on a project it takes them to single-portfolio.php displaying the associated project.

Everything is working how it should and is styled correctly, but now I would like to have the gallery, which is on archive-portfolio.php, also display under each project, which is on single-portfolio.php, making navigation between projects easy. It would also be great if when it displayed the gallery the link for the project that the user was on was excluded from the gallery.

I've tried inserting

<?php wp_get_archives(); ?>

into my single-portfolio.php template, but I couldn't seem to get it to work how I wanted. I couldn't get it to grab my custom posts and it would just display a month link that linked to my regular posts. I need it to just display my custom posts and the gallery that is on archive-portfolio.php. (Basically I just want to insert archive-portfolio.php into single-portfolio.php under the content of single-portfolio.php)

This is my first Wordpress site and I am learning it all on my own as I go. I've tried searching for a solution on my own, but everything I find seems to just be about how to create a custom post type, which I already figured out. I am still developing my site locally which is why I can't link to it right now, but to give you an idea of what I'm going for you can check out this site which was made with Cargo:

http://www.timboelaars.nl/help-ink

Basically, I want the same functionality as the example site; I just want the gallery to display under the project.

Like always, any help would be much appreciated! I've been struggling with a solution for this for a couple of days now and have been avoiding it, but the site is almost done and it can't be avoided anymore. I could really use some help on this. Thanks in advance!



(EDIT: As requested by the comment below, here is what my custom php files look like)

archive-portfolio.php:

<!-- get_header -->
<?php get_header(); ?>
<!-- END get_header -->         

            <!-- #content -->
            <div id="content">

                <!-- #inner-content -->
                <div id="inner-content" class="wrap clearfix">

                    <!-- #main -->
                    <div id="main" class="twelvecol first clearfix" role="main">

                        <!-- have_posts -->
                        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

                        <!-- article -->
                        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?> role="article">

                            <!-- .entry-content -->
                            <section class="entry-content clearfix portfolio-gallery">

                                <!-- PORTFOLIO PROJECT LINK -->
                                <a href="<?php the_permalink() ?>">

                                    <!-- .portfolio-project -->
                                    <figure class="portfolio-project">

                                        <!-- custom header -->
                                        <header class="portfolio-project-title">
                                            <h1 class="bigtext">
                                                <div>
                                                    <?php
                                                        global $post;
                                                            $text = get_post_meta( $post->ID, 'juroto_custom_header', true );
                                                        echo $text;
                                                    ?>
                                                </div>
                                            </h1>                                   
                                        </header> <!-- END custom header -->                                    

                                        <!-- the_excerpt -->
                                        <figcaption class="portfolio-project-excerpt">
                                            <?php the_excerpt(); ?>
                                        </figcaption> <!-- END the_excerpt -->

                                        <!-- .black-filter -->
                                        <div class="black-filter"></div>
                                        <!-- END .black-filter -->

                                        <!-- featured image -->
                                        <?php
                                            if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
                                                the_post_thumbnail('thumbnail-bw', array('class'=>'bw-image-fade'));
                                                the_post_thumbnail('thumbnail');
                                            } 
                                        ?> <!-- END featured image -->

                                    </figure> <!-- END .portfolio-project -->

                                </a> <!-- END PORTFOLIO PROJECT LINK -->

                            </section> <!-- END .entry-content -->

                        </article> <!-- END article -->

                        <?php endwhile; ?> <!-- END have_posts -->

                        <?php else : ?>

                            <!-- #post-not-found -->
                            <article id="post-not-found" class="hentry clearfix">
                                <header class="article-header">
                                    <h1><?php _e("Oops, Post Not Found!", "bonestheme"); ?></h1>
                                </header>
                                <section class="entry-content">
                                    <p><?php _e("Uh Oh. Something is missing. Try double checking things.", "bonestheme"); ?></p>
                                </section>
                                <footer class="article-footer">
                                    <p><?php _e("This is the error message in the custom posty type archive template.", "bonestheme"); ?></p>
                                </footer>
                            </article>

                        <?php endif; ?> <!-- END #post-not-found -->

                    </div> <!-- END #main -->

                </div> <!-- END #inner-content -->

            </div> <!-- END #content -->

<!-- get_footer -->
<?php get_footer(); ?>
<!-- END get_footer -->

Basically I want to insert that loop that calls each article (or as I refer to it portfolio project) into single-portfolio.php under the project that is being shown. Here is what single-portfolio.php looks like.

single-portfolio.php:

<!-- get_header -->
<?php get_header(); ?>
<!-- END get_header -->

            <!-- #content -->
            <div id="content">

                <!-- #inner-content -->
                <div id="inner-content" class="wrap clearfix">

                    <!-- #main -->
                    <div id="main" class="twelvecol first clearfix" role="main">

                        <!-- have_posts -->
                        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

                        <!-- article -->
                        <article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article">

                            <!-- .article-header -->
                            <header class="article-header">

                                <!-- .bigtext -->
                                <h1 class="bigtext">
                                    <div>
                                        <!-- the_title -->
                                        <?php the_title(); ?>
                                        <!-- END the_title -->
                                    </div>
                                </h1> <!-- END .bigtext -->

                            </header> <!-- END article header -->

                            <!-- .entry-content -->
                            <section class="entry-content clearfix">

                                <!-- GALLERY -->                                
                                <?php
                                    $jurotos_gallery = array( 
                                        // OPTIONS FOR THE GALLERY 
                                        'numberposts'       => -1, // Using -1 loads all posts or in this case images  
                                        'orderby'           => 'menu_order', // This ensures images are in the order set in the page media manager. To change the order of the images go to the post, click add media, click the drop down menu, select uploaded to this post, and just drag and drop the images in the order you want them to appear. When you're done just close the media manager, you don't need to update the post or insert image or anything.  
                                        'order'             => 'ASC', // ASC or DESC. ASC shows order as is in the media manager and DESC shows the reverse order (so the last image is first and so on)
                                        'post_mime_type'    => 'image', // Make sure it doesn't pull other resources, like videos  
                                        'post_parent'       => $post->ID, // *Important part - ensures the associated images are loaded 
                                        'post_status'       => null, 
                                        'post_type'         => 'attachment',
                                        'size'              => 'full',  // thumbnail, medium, large or full
                                        'include'           => '', // could choose to include something else
                                        'exclude'           => get_post_thumbnail_id( $post->ID ), // excludes thumbnail/featured image from being part of the gallery
                                    );  

                                    $images = get_children( $jurotos_gallery );
                                ?> 

                                <?php if($images){ ?>  
                                    <div class="flexslider">
                                        <ul class="slides">
                                            <?php foreach($images as $image){ ?>  
                                                <li>
                                                    <img src="<?php echo $image->guid; ?>" alt="<?php echo $image->post_title; ?>" title="<?php echo $image->post_title; ?>" />
                                                </li> 
                                            <?php } ?>
                                        </ul>  
                                    </div>  
                                <?php } ?>                              
                                <!-- END GALLERY -->  

                                <!-- the_content -->
                                <div id="accordion">
                                    <h3>Brief</h3>
                                        <div class="juroto-text-columns">
                                            <?php the_content(); ?>
                                        </div>
                                </div>
                                <!-- END the_content -->

                            </section> <!-- END .entry-content -->

                        </article> <!-- END article -->

                        <?php endwhile; ?> <!-- END have_posts -->          

                        <?php else : ?>

                            <!-- #post-not-found -->
                            <article id="post-not-found" class="hentry clearfix">
                                <header class="article-header">
                                    <h1><?php _e("Oops, Post Not Found!", "bonestheme"); ?></h1>
                                </header>
                                <section class="entry-content">
                                    <p><?php _e("Uh Oh. Something is missing. Try double checking things.", "bonestheme"); ?></p>
                                </section>
                                <footer class="article-footer">
                                    <p><?php _e("This is the error message in the single-portfolio.php template.", "bonestheme"); ?></p>
                                </footer>
                            </article>

                        <?php endif; ?> <!-- END #post-not-found -->

                    </div> <!-- END #main -->

                </div> <!-- END #inner-content -->

            </div> <!-- END #content -->

<!-- get_footer -->
<?php get_footer(); ?>
<!-- END get_footer -->





(EDIT: below is an excerpt of the loop from archive-portfolio.php that displays all my custom portfolio posts. I have these posts arranged and styled to look like a gallery of posts/projects. This is what I would like to have show up under a post/project when you are on the post/project page which is being displayed by single-portfolio.php. Basically I need to have this loop that gathers all the custom posts and arranges it into a gallery in single-portfolio.php under the loop in single-portfolio.php that gathers the information for that specific post/project, but I don't know how to do it. Is there some code like:

<?php get_archive-portfolio(); ?> 

that I could use in single-portfolio.php to display the gallery of custom posts?)

loop from archive-portfolio.php that displays portfolio gallery:

<!-- have_posts -->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<!-- article -->
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?> role="article">

    <!-- .entry-content -->
    <section class="entry-content clearfix portfolio-gallery">

        <!-- PORTFOLIO PROJECT LINK -->
        <a href="<?php the_permalink() ?>">

            <!-- .portfolio-project -->
            <figure class="portfolio-project">

                <!-- custom header -->
                <header class="portfolio-project-title">
                    <h1 class="bigtext">
                        <div>
                            <?php
                                global $post;
                                    $text = get_post_meta( $post->ID, 'juroto_custom_header', true );
                                echo $text;
                            ?>
                        </div>
                    </h1>                                   
                </header> <!-- END custom header -->                                    

                <!-- the_excerpt -->
                <figcaption class="portfolio-project-excerpt">
                    <?php the_excerpt(); ?>
                </figcaption> <!-- END the_excerpt -->

                <!-- .black-filter -->
                <div class="black-filter"></div>
                <!-- END .black-filter -->

                <!-- featured image -->
                <?php
                    if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
                        the_post_thumbnail('thumbnail-bw', array('class'=>'bw-image-fade'));
                        the_post_thumbnail('thumbnail');
                    } 
                ?> <!-- END featured image -->

            </figure> <!-- END .portfolio-project -->

        </a> <!-- END PORTFOLIO PROJECT LINK -->

    </section> <!-- END .entry-content -->

</article> <!-- END article -->

<?php endwhile; ?> <!-- END have_posts -->

<?php else : ?>

    <!-- #post-not-found -->
    <article id="post-not-found" class="hentry clearfix">
        <header class="article-header">
            <h1><?php _e("Oops, Post Not Found!", "bonestheme"); ?></h1>
        </header>
        <section class="entry-content">
            <p><?php _e("Uh Oh. Something is missing. Try double checking things.", "bonestheme"); ?></p>
        </section>
        <footer class="article-footer">
            <p><?php _e("This is the error message in the custom posty type archive template.", "bonestheme"); ?></p>
        </footer>
    </article>

<?php endif; ?> <!-- END #post-not-found -->





(EDIT: below is portfolio.php which is a function file in my Wordpress theme that creates my custom-post-type:'portfolio', stores data for it, and creates a portfolio section in my admin area. This file also creates custom taxonomy for the custom post type and defines how many custom post types will be shown per page on its archive page, which I set to be all of the custom posts. I separated this file from my themes function file to keep it a bit more organized.)

portfolio.php function:

<?php
/****************************************
Creates Portfolio section in the admin 
area and custom posts called Projects
*****************************************/

function create_portfolio_section() { 
    // creating (registering) the custom type 
    register_post_type( 'portfolio', /* (http://codex.wordpress.org/Function_Reference/register_post_type) *IMPORTANT: If you change this, remember to resave/update permalinks from Wordpress admin menu under Setting/Permalinks for the page to display properly. Forgetting to do this will most likely lead you to the 404 error page */
        // All the options for this post type
        array('labels' => array(
            'name' => __('Portfolio', 'bonestheme'), /* This is the Title of the Group */
            'singular_name' => __('Project', 'bonestheme'), /* This is the individual type */
            'all_items' => __('All Projects', 'bonestheme'), /* the all items menu item */
            'add_new' => __('Add New Project', 'bonestheme'), /* The add new menu item */
            'add_new_item' => __('Add New Project', 'bonestheme'), /* Add New Display Title */
            'edit' => __( 'Edit Project', 'bonestheme' ), /* Edit Dialog */
            'edit_item' => __('Edit Project', 'bonestheme'), /* Edit Display Title */
            'new_item' => __('New Project', 'bonestheme'), /* New Display Title */
            'view_item' => __('View Project', 'bonestheme'), /* View Display Title */
            'search_items' => __('Search Project', 'bonestheme'), /* Search Project Title */ 
            'not_found' =>  __('No Projects found', 'bonestheme'), /* This displays if there are no entries yet */ 
            'not_found_in_trash' => __('No Projects found in the Trash', 'bonestheme'), /* This displays if there is nothing in the trash */
            'parent_item_colon' => ''
            ), /* end of arrays */
            'description' => __( 'This is a Portfolio Project', 'bonestheme' ), /* Project Description */
            'public' => true,
            'publicly_queryable' => true,
            'exclude_from_search' => false,
            'show_ui' => true,
            'query_var' => true,
            'menu_position' => 5, /* this is what order you want it to appear in on the left hand side menu */ 
            'menu_icon' => get_stylesheet_directory_uri() . '/library/images/custom-post-icon.png', /* the icon for the custom post type menu */
            'rewrite'   => array( 'slug' => 'portfolio', 'with_front' => false ), /* you can specify its url slug *IMPORTANT: If you change this, remember to resave/update permalinks from Wordpress admin menu under Setting/Permalinks for the page to display properly. Forgetting to do this will most likely lead you to the 404 error page */
            'has_archive' => 'portfolio', /* you can rename the slug here *IMPORTANT: If you change this, remember to resave/update permalinks from Wordpress admin menu under Setting/Permalinks for the page to display properly. Forgetting to do this will most likely lead you to the 404 error page */
            'capability_type' => 'post',
            'hierarchical' => false,
            /* the next one is important, it tells what's enabled in the post editor */
            'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'sticky')
        ) /* end of options */
    ); /* end of register post type */

    /* this adds your post categories to the Portfolio section */
    register_taxonomy_for_object_type('category', 'portfolio');
    /* this adds your post tags to the Portfolio section */
    register_taxonomy_for_object_type('post_tag', 'portfolio');

} 

    // adding the function to the Wordpress init
    add_action( 'init', 'create_portfolio_section');

    /*
    for more information on taxonomies, go here:
    http://codex.wordpress.org/Function_Reference/register_taxonomy
    */

    // this adds Portfolio Categories to the Portfolio section
    register_taxonomy( 'portfolio_cat', 
        array('portfolio'), /* if you change the name of register_post_type( 'portfolio', then you have to change this */
        array('hierarchical' => true,     /* if this is true, it acts like categories */             
            'labels' => array(
                'name' => __( 'Portfolio Categories', 'bonestheme' ), /* name of the custom taxonomy */
                'singular_name' => __( 'Portfolio Category', 'bonestheme' ), /* single taxonomy name */
                'search_items' =>  __( 'Search Portfolio Categories', 'bonestheme' ), /* search title for taxomony */
                'all_items' => __( 'All Portfolio Categories', 'bonestheme' ), /* all title for taxonomies */
                'parent_item' => __( 'Parent Portfolio Category', 'bonestheme' ), /* parent title for taxonomy */
                'parent_item_colon' => __( 'Parent Portfolio Category:', 'bonestheme' ), /* parent taxonomy title */
                'edit_item' => __( 'Edit Portfolio Category', 'bonestheme' ), /* edit custom taxonomy title */
                'update_item' => __( 'Update Portfolio Category', 'bonestheme' ), /* update title for taxonomy */
                'add_new_item' => __( 'Add New Portfolio Category', 'bonestheme' ), /* add new title for taxonomy */
                'new_item_name' => __( 'New Portfolio Category Name', 'bonestheme' ) /* name title for taxonomy */
            ),
            'show_admin_column' => true, 
            'show_ui' => true,
            'query_var' => true,
            'rewrite' => array( 'slug' => 'custom-slug' ),
        )
    );   

    // this adds Portfolio Tags to the Portfolio section
    register_taxonomy( 'portfolio_tag', 
        array('portfolio'), /* if you change the name of register_post_type( 'portfolio', then you have to change this */
        array('hierarchical' => false,    /* if this is false, it acts like tags */                
            'labels' => array(
                'name' => __( 'Portfolio Tags', 'bonestheme' ), /* name of the custom taxonomy */
                'singular_name' => __( 'Portfolio Tag', 'bonestheme' ), /* single taxonomy name */
                'search_items' =>  __( 'Search Portfolio Tags', 'bonestheme' ), /* search title for taxomony */
                'all_items' => __( 'All Portfolio Tags', 'bonestheme' ), /* all title for taxonomies */
                'parent_item' => __( 'Parent Portfolio Tag', 'bonestheme' ), /* parent title for taxonomy */
                'parent_item_colon' => __( 'Parent Portfolio Tag:', 'bonestheme' ), /* parent taxonomy title */
                'edit_item' => __( 'Edit Portfolio Tag', 'bonestheme' ), /* edit custom taxonomy title */
                'update_item' => __( 'Update Portfolio Tag', 'bonestheme' ), /* update title for taxonomy */
                'add_new_item' => __( 'Add New Portfolio Tag', 'bonestheme' ), /* add new title for taxonomy */
                'new_item_name' => __( 'New Portfolio Tag Name', 'bonestheme' ) /* name title for taxonomy */
            ),
            'show_admin_column' => true,
            'show_ui' => true,
            'query_var' => true,
        )
    ); 

    /*
        looking for custom meta boxes?
        check out this fantastic tool:
        https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress
    */



// Custom Posts Per Page
function portfolio_posts_per_page($query)
{
    switch ( $query->query_vars['post_type'] )
    {
        case 'portfolio':  // Post Type named 'portfolio'
            $query->query_vars['posts_per_page'] = -1; // -1 makes all posts shown on one page, positive numbers show that number of posts per page.
            break;

        // If you have more custom post types and you want to have the posts per page different than the journal/blog settings copy and past the code above and assign proper post type name and desired posts per page
        // EXAMPLE
        /*
        case '<insert post type name here>':  // Post Type named 'portfolio'
            $query->query_vars['posts_per_page'] = <insert desiered posts per page number here>; // -1 makes all posts shown on one page, positive numbers show that number of posts per page.
            break;
        */

        default:
            break;
    }
    return $query;
}

if( !is_admin() )
{
    add_filter( 'pre_get_posts', 'portfolio_posts_per_page' );
}

?>
1
can you please post your custom page code, so that we can get a better idea what your working withDavid Chase
Ofcourse, no problem. I edited the original post to show both the archive-portfolio.php and single-portfolio.php files. Hopefully that is what you meant, but if you need anything else I'd be happy to post that too.juroto
do you just want query your custom post data, and put that content inside of the single-portfolio.phpDavid Chase
Umm, I'm still not quite sure what querying means, but if querying my custom post data means getting the gallery I have showing on archive-portfolio.php and putting it under the project/post in single-portfolio.php, then yes.juroto
Is there some sort of tag like <?php get_archive-portfolio(); ?> that I could just insert into single-portfolio.php where I want the gallery to appear?juroto

1 Answers

1
votes

You are trying to include an archive template, listing multiple posts, below a singular post. To do this, you will need to run multiple loops -- One for your main post, one for the list of posts below. The codex has information on multiple loops.

(Edit: Don't use query_posts as described below because it will alter the main post loop which can cause problems, as noted by Brad Dalton in the comments. Use a new WP_Query object instead. The code remains very similar to the one I described below. Read more.)

First, below the main post, query the list of other posts, using query_posts() by creating a new WP_Query object. You can find information on how to query your posts in the codex. (You probably only want post-type portfolio, only published posts, etc.) Then, use get_template_part() to include your archive template. Finally, don't forget to call wp_reset_query().

query_posts('post_type=portfolio'); # Use WP_Query arguments accordingly
get_template_part('archive-portfolio');
wp_reset_query();