问题描述
我有两个单独的页面,显示了不同类别的列表,这些列表链接到wordpress中的完整文章.这些都当前在我的主题中的single.php上打开,但是类别需要在每个页面上以不同的样式设置.
I have two separate pages showing a list of different categories linking to the full post in wordpress. These both currently open on single.php in my theme but The categories need to be styled differently on each page.
我已经创建了模板页面,但是不知道如何在single.php之外的其他页面上打开帖子
I have created the template page but do not know how to open posts on another page other than single.php
为简单起见:如何在single.php的另一个版本上打开帖子
to simplify: how do I open posts on another version of single.php
打开全部帖子的代码是:
the code I have that opens the full posts are:
<?php // PAGE LINK/TITLE
if (is_page()) {
$cat=get_cat_ID($post->post_title); //use page title to get a category ID
$posts = get_posts ("category_name=case-study&posts_per_page=10");
if ($posts) {
foreach ($posts as $post):
setup_postdata($post);
?>
<div class="serve-inner-split">
<div id="case-split">
<div id="case-left" class=" serve-left">
<div id="case-study-content">
<h1 class="case-study-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
<p><?php //PULLS IN EXCERPT
$my_excerpt = get_the_excerpt();
if ( '' != $my_excerpt ) {
// Some string manipulation performed
}
echo $my_excerpt; // Outputs the processed value to the page
?>
</p>
<a href="#" class="header-quote">READ CASE STUDY</a>
</div>
</div>
<div id="case-right" class="serve-grey">
<?php
if ( has_post_thumbnail() ) { // PULLS IN IMAGE check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail();
}
?>
</div>
</div>
</div>
<?php endforeach;
}
}
?>
推荐答案
您好:)我可以通过为每种情况创建自定义帖子类型来实现此目的,您需要以不同方式显示单个帖子.在这种情况下,您可以参考WP Codex https://codex.wordpress.org/Post_Types .最终,它将允许您根据需要创建尽可能多的单个帖子模板.
Hello :) I would achieve this by creating custom post type for each case you need to display the single post differently. You may refer to WP Codex https://codex.wordpress.org/Post_Types on this case. Eventually it will allow you to create as much single post templates as you want.
这篇关于在其他页面中打开Wordpress帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!