关于页面/ slug架构的建议

时间:2016-08-31 15:56:39

标签: wordpress

我正在寻找一些关于如何最好地为我正在构建的WP站点创建页面/ slug结构的sage建议。这是一个展示创意作品的投资组合网站。我目前为项目组合/工作项及其关联客户创建了几种自定义帖子类型,并使用高级自定义字段插件在这些项目之间创建了关系。所有这一切都很棒。我正在努力的是如何创建最好的URL结构。

我已经创建了以下页面并且运行良好:

/ work / - 显示所有工作的索引页面,无论客户端如何 / clients / - 所有客户的列表

我需要创建以下页面:

/ clients / client / - 此页面将显示与特定客户端关联的所有工作。这是我在努力的地方。我需要帮助了解如何使用页面模板系统来设置正确的页面slu ..我可以使用页面slugs作为我的WP查询的一部分吗?我可以根据自定义帖子类型进行查询吗?如何命名页面模板文件以使其正常工作?

感谢任何人可以提供的任何建议和/或示例。谢谢。

2 个答案:

答案 0 :(得分:1)

WordPress offers an easy mechanism to handle pages and posts as well that are being created and rendered. It is us who has to take up the challenge to do those wonderful designs and tasks that we need. Moving on to the following topic of page and slug architecture we shall discuss in detail.

First let us look onto the following thing.

Creating Page Template for Custom Posts Type

Ex: If you are creating the post type called news the WordPress system will look for the following structures.

  1. single-{post-type}.php
  2. archive-{post-type}.php

single-{post_type}.php

If your custom post type were 'news', and/or query_var = "news", WordPress would look for single-news.php to display the single or permalink of the post.

archive-{post_type}.php

If your custom post type were 'news', and/or query_var = "news", WordPress would look for archive-news.php to display the archive of posts.

If these files are not available in your Theme's directory WordPress will look for archive.php and single.php, respectively. If even these files are not present it will default to index.php.

Template File will be like this.

<?php 
$args = array( 'post_type' => 'news', 'posts_per_page' => 10,'post_status'=>'publish','orderby'=>'ID','order'=>'DESC' );
$the_query = new WP_Query( $args ); 
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><?php the_title(); ?></h2>
<div class="entry-content">
<?php the_content(); ?> 
</div>
<?php wp_reset_postdata(); ?>
<?php else:  ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

Hence from the above code you can display the Latest Posts from News category in the count of 10.

If you need the count to be infinite you have to change the post_per_page=10 to post_per_page=-1.

Hope so this reference and advice that i have tried to explain will be helpful for you. Still if you face any issues about my explanation comment over to my answer and i am there to help you.

答案 1 :(得分:0)

我没有按照这个确切的路线来解决我的问题,因为我使用的是高级自定义关系插件。我的解决方案与此类似:https://www.advancedcustomfields.com/resources/querying-relationship-fields/ - 但您的回复非常有帮助,让我走上正轨,谢谢!