【问题标题】:Get either the_content or the_excerpt depending upon custom page type根据自定义页面类型获取 the_content 或 the_excerpt
【发布时间】:2013-10-14 13:55:34
【问题描述】:

我创建了一个名为“category-blog.php”的类别模板,旨在显示我的博客条目的所有摘录。然而,一种自定义帖子类型(引用)依赖于显示内容,而不是摘录,所以我需要创建一个简单的“if”参数来说明“如果这是一个标准帖子,则只显示摘录,但如果这是一个引用发布,显示内容。我假设我必须对 (get_template_part) 做一些事情,但我不确定是什么。所有这些都发生在循环中。

<div class="entry-content">
<php if custom page type is 'quote', then...
<?php the_content(); ?>
<else...
<?php the_excerpt(); ?>

【问题讨论】:

    标签: php wordpress templates


    【解决方案1】:

    使用函数get_post_type()

    <div class="entry-content">
    <?php
    if(get_post_type() == 'quote'){
       the_content();
    }else{
       //something else
    }
    ?>
    </div>
    

    http://codex.wordpress.org/Function_Reference/get_post_type

    【讨论】:

    • 我不确定这是否适用于我的情况。如果我使用这个:&lt;?php if(get_post_type() == 'quote'){ the_content(); }else{ the_excerpt(); } ?&gt;... 它仍然显示报价自定义页面的摘录。
    • 您的自定义帖子类型是否命名为quote
    • 是的。我正在使用具有不同帖子格式的二十三个主题的孩子,其中一种称为“报价”。它使用页面模板'content-quote.php'。在 WP 的帖子编辑区域中,它有一个格式列表,其中之一是“引用”。
    猜你喜欢
    • 1970-01-01
    • 2013-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 2019-04-28
    • 1970-01-01
    • 2013-08-28
    相关资源
    最近更新 更多