我正在我的 Wordpress 作品集网站上工作,并为我的作品集部分创建了一个自定义帖子类型。当用户点击我的投资组合链接时,它会将他们带到显示我所有项目的画廊的archive-portfolio.php,当他们点击一个项目时,它会将他们带到显示相关项目的single-portfolio.php。
一切都在按应有的方式工作并且样式正确,但是现在我希望将位于 archive-portfolio.php 上的画廊也显示在位于 single-portfolio.php 上的每个项目下,从而使项目之间的导航变得容易. 如果当它显示画廊时,用户所在项目的链接被排除在画廊之外,那也很棒。
我试过插入
<?php wp_get_archives(); ?>
到我的 single-portfolio.php 模板中,但我似乎无法让它按我想要的方式工作。我无法让它抓取我的自定义帖子,它只会显示一个链接到我的常规帖子的月份链接。我需要它来显示我的自定义帖子和archive-portfolio.php 上的图库。(基本上我只是想将archive-portfolio.php插入到single-portfolio.php内容下的single-portfolio.php中)
这是我的第一个 Wordpress 网站,我正在自己学习。我试过自己寻找解决方案,但我发现的一切似乎都只是关于如何创建自定义帖子类型,我已经想通了。我仍在本地开发我的网站,这就是为什么我现在无法链接到它,但为了让您了解我的目标,您可以查看这个使用 Cargo 制作的网站:
http://www.timboelaars.nl/help-ink
基本上,我想要与示例站点相同的功能;我只是希望画廊在项目下显示。
像往常一样,任何帮助将不胜感激!几天来,我一直在努力寻找解决方案,并且一直在避免它,但是该站点几乎完成了,再也无法避免了。我真的可以在这方面使用一些帮助。提前致谢!
(编辑:根据下面的评论要求,这是我的自定义 php 文件的样子)
存档-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 -->
基本上,我想将调用每篇文章(或我称之为投资组合项目)的循环插入到正在显示的项目下的 single-portfolio.php 中。这是 single-portfolio.php 的样子。
单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 -->
(编辑:下面是archive-portfolio.php循环的摘录,它显示了我所有的自定义投资组合帖子。我将这些帖子安排和样式看起来像帖子/项目的画廊。这就是我想要展示的当您在由 single-portfolio.php 显示的帖子/项目页面上时,在帖子/项目下。基本上我需要有这个循环来收集所有自定义帖子并将其排列到单个组合中的画廊中。 php 在 single-portfolio.php 中的循环下收集特定帖子/项目的信息,但我不知道该怎么做。是否有类似的代码:
<?php get_archive-portfolio(); ?>
我可以在 single-portfolio.php 中使用来显示自定义帖子的画廊吗?)
从显示投资组合库的 archive-portfolio.php 循环:
<!-- 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 -->
(编辑:下面是portfolio.php,它是我的Wordpress主题中的一个函数文件,它创建我的自定义帖子类型:'portfolio',为其存储数据,并在我的管理区域创建一个投资组合部分。这个文件还创建自定义自定义帖子类型的分类,并定义在其存档页面上每页将显示多少自定义帖子类型,我将其设置为所有自定义帖子。我将此文件与我的主题函数文件分开以使其更有条理.)
投资组合.php 功能:
<?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' );
}
?>