这个带有 3 个条件的 php if 语句有什么问题?

发布于 2024-11-17 18:29:20 字数 1805 浏览 1 评论 0原文

以下 if 语句有 3 个条件:

<?php if ( is_archive() ) : ?>

    <?php $topic_tag_term = get_query_var( 'term' ); ?>

    <?php // Display the top topics of current forum
        $args = array(
            'post_type' => 'topic',
            'posts_per_page' => '3',
            'topic-tag' => $topic_tag_term,
            'r_sortby' => 'highest_rated',
            'r_orderby' => 'desc',
            'order' => 'DESC'
        );
    ?>

    <?php $term = $wp_query->queried_object; ?>
    <p>The following are a list of topic tagged as <strong><?php echo $term->name ?></strong>.</p>

    <?php if ( bbp_current_user_can_access_create_topic_form() ) : ?>

        <a id="new-entry" href="<?php echo home_url( '/' ); ?>/create-topic">Start a new topic</a>

    <?php endif; ?>

<?php if ( is_page_template() ) : ?>

    <?php // Display the top topics of current forum
        $args = array(
            'post_type' => 'topic',
            'posts_per_page' => '3',
            'r_sortby' => 'highest_rated',
            'r_orderby' => 'desc',
            'order' => 'DESC',
            'meta_key' => '_bbp_reply_count',
            'meta_value' => '1',
            'meta_compare' => '<'
        );
    ?>

<?php else : ?>

    <?php // Display the top topics of current forum
        $args = array(
            'post_type' => 'topic',
            'posts_per_page' => '3',
            'post_parent' => $post->ID,
            'r_sortby' => 'highest_rated',
            'r_orderby' => 'desc',
            'order' => 'DESC'
        );
    ?>

<?php endif; ?>

由于某种原因,此代码破坏了我的页面。

这有什么问题吗?

The following if statement has 3 conditions:

<?php if ( is_archive() ) : ?>

    <?php $topic_tag_term = get_query_var( 'term' ); ?>

    <?php // Display the top topics of current forum
        $args = array(
            'post_type' => 'topic',
            'posts_per_page' => '3',
            'topic-tag' => $topic_tag_term,
            'r_sortby' => 'highest_rated',
            'r_orderby' => 'desc',
            'order' => 'DESC'
        );
    ?>

    <?php $term = $wp_query->queried_object; ?>
    <p>The following are a list of topic tagged as <strong><?php echo $term->name ?></strong>.</p>

    <?php if ( bbp_current_user_can_access_create_topic_form() ) : ?>

        <a id="new-entry" href="<?php echo home_url( '/' ); ?>/create-topic">Start a new topic</a>

    <?php endif; ?>

<?php if ( is_page_template() ) : ?>

    <?php // Display the top topics of current forum
        $args = array(
            'post_type' => 'topic',
            'posts_per_page' => '3',
            'r_sortby' => 'highest_rated',
            'r_orderby' => 'desc',
            'order' => 'DESC',
            'meta_key' => '_bbp_reply_count',
            'meta_value' => '1',
            'meta_compare' => '<'
        );
    ?>

<?php else : ?>

    <?php // Display the top topics of current forum
        $args = array(
            'post_type' => 'topic',
            'posts_per_page' => '3',
            'post_parent' => $post->ID,
            'r_sortby' => 'highest_rated',
            'r_orderby' => 'desc',
            'order' => 'DESC'
        );
    ?>

<?php endif; ?>

For some reason this code is breaking my page.

What is wrong with it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

李不 2024-11-24 18:29:20
<?php if ( is_page_template() ) : ?>

至少应该是

<?php elseif ( is_page_template() ) : ?>

这是我能看到的错误。

<?php if ( is_page_template() ) : ?>

should be

<?php elseif ( is_page_template() ) : ?>

at least this is the error I can see.

北恋 2024-11-24 18:29:20

if (testcase) 后面的冒号不应该出现。我认为您对 的使用感到困惑?

检查手册:这里

无意冒犯,但是每一行上的所有 都只是废话。

The colons after your if (testcase) should not be there. I think your confusing the use of ?

Check the manual: here

No offence but all those <?php ?> on every line are just nonsense.

桃扇骨 2024-11-24 18:29:20

该行末尾没有分号。

<strong><?php echo $term->name ?></strong>

This line has no semi colon at the end.

<strong><?php echo $term->name ?></strong>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文