我正在我的Wordpress公文包网站上工作,并为我的公文包部分创建了一个自定义帖子类型。当用户单击my portfolio链接时,会将他们带到archive-portfolio.php,其中显示我所有项目的图库;当用户单击项目时,会将他们带到single-portfolio.php,其中显示关联的项目。
一切都正常工作,样式正确,但现在我想让archive-portfolio.php上的gallery也显示在single-portfolio.php上的每个项目下,使项目之间的导航变得容易。如果在显示图库时,用户所在项目的链接被排除在图库之外,这也会很好。
我试过插入
<?php wp_get_archives(); ?>
进入我的single-portfolio.php模板,但我似乎无法让它按我想要的方式工作。我无法让它抓取我的自定义帖子,它只会显示一个月链接,链接到我的常规帖子。我需要它来显示我的自定义帖子和archive-portfolio.php上的图库。(基本上我只想将archive-portfolio.php插入single-portfolio.php中single-portfolio.php的内容下)
这是我的第一个Wordpress网站,我正在自己学习。我试着自己寻找解决方案,但我找到的一切似乎都是关于如何创建自定义帖子类型,我已经找到了。我仍在本地开发我的网站,这就是我现在无法链接到它的原因,但为了让您了解我的目的,您可以查看这个用货物制作的网站:
http://www.timboelaars.nl/help-ink
基本上,我想要与示例站点相同的功能;我只想在项目下显示图库。
像往常一样,任何帮助都将不胜感激!这几天来,我一直在努力寻找解决方案,并一直在回避它,但该网站几乎完成了,再也无法回避了。我真的需要一些帮助。提前谢谢
(编辑:根据下面评论的要求,以下是我的自定义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的外观。
<!-- 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.Basica显示的帖子/项目页面上时,这就是我希望在帖子/项目下显示的内容lly我需要有一个循环来收集所有自定义帖子,并将其排列到single-portfolio.php中single-portfolio.php循环下的gallery中,该循环用于收集特定帖子/项目的信息,但我不知道如何执行。是否有类似以下代码:
<?php get_archive-portfolio(); ?>
我可以在single-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主题中的一个函数文件,它创建我的自定义后类型:'投资组合',为它存储数据,并在我的管理区域中创建一个投资组合部分。该文件还为自定义帖子类型创建自定义分类法,并定义在其存档页面上每页显示多少自定义帖子类型,我将其设置为所有自定义帖子。我把这个文件从我的主题函数文件中分离出来,让它更有条理。(
<?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' );
}
?>
您正试图在一篇单篇文章下面包含一个归档模板,其中列出了多篇文章。要做到这一点,您需要运行多个循环——一个用于主帖子,一个用于下面的帖子列表。法典中有关于多个循环的信息。
(编辑:不要使用下面描述的query_posts,因为它会改变可能导致问题的主帖子循环,正如布拉德·道尔顿在评论中指出的那样。改为使用新的WP_Query对象。代码与我下面描述的代码非常相似。阅读更多。)
首先,在主帖子下方,通过创建新的WP\u查询对象,使用query\u posts()
查询其他帖子的列表。你可以在法典中找到关于如何查询你的帖子的信息。(您可能只需要文章类型组合、仅发布的文章等)然后,使用get\u template\u part()
包含归档模板。最后,不要忘记调用wp\u reset\u query()
。
query_posts('post_type=portfolio'); # Use WP_Query arguments accordingly
get_template_part('archive-portfolio');
wp_reset_query();
我是新来的wordpress, im创建一个自定义职位与字段的custom_meta_box(位置,着装) 所以在我的自定义帖子列表中,我想查看我在custom_meta_box上创造的价值。 这是我目前的代码:
我有一个自定义的帖子类型设置,有许多类别和子类别。 我试图做的是创建一个页面,显示特定类别中的所有帖子,并使用一个菜单列出所有类别子类别,以便可以过滤帖子。 我已尝试复制存档模板并将其重命名为分类法-(我的自定义分类法)。php,如果我转到slug,它会显示某些帖子,并使用
我创建了一个自定义超文本标记语言归档博客页面,我想在其中放置WordPress帖子。自定义页面有几个不同的布局,因此在帖子中循环只是重新生成我试图避免的整个页面。我想做的是循环通过每个帖子,然后将该帖子放在相关的档案中。 因此,第1列进入第1列第1列,第2列进入第2列第1列,第3列进入第2列第2列,第4列进入第2列第3列,以此类推。。。 如果这是不可能的,有没有一种方法,我可以有一个代码块,例如,
我想向Wordpress中的现有页面添加一些额外的表单字段。每当您编辑帖子或页面时,此页面都会被重定向。我的问题是我不知道在哪里找到这个文件或者它的名字。 我需要知道我需要编辑什么文件才能添加新的输入。 只有当您是管理员并登录到仪表板时,才会看到此页面。 我使用wordpress边缘洗牌主题。
我已经使用代码设置了WordPress自定义帖子类型。我已经设法让自定义帖子显示在“归档”页面中,但如果我单击“归档”页面中的链接,WP无法找到单个帖子页面。 我想我可能对定制的post permalinks有问题。希望有人能帮我 functions.php 页面模板 要显示自定义帖子,我设置了一个带有WP查询的新页面模板: 页面模板代码似乎工作和所有自定义帖子显示预期但当我点击标题链接我得到一个
在我正在构建的当前网站中,我构建了以下功能。 对当前形势给予更好的理解。 有一个叫做博客的页面。此页面显示列表中的所有博客(帖子)。所有职位的类别都有一个例外。用户可以选择一个类别。一旦用户单击它,用户将转到该类别。php并查看所有具有该特定类别的帖子。 我想创建相同的场景,但不是用自定义帖子类型。我有一个模板部分;offer-list-template.php offer-list-templa