如何让我的缩略图图像使用类别URL?

时间:2018-01-05 04:29:13

标签: php wordpress

我正在尝试使用Wordpress滑块并将缩略图上的链接更改为类别网址而不是固定链接(同时仍然从帖子中拉出缩略图)。我开始使用一个使用永久链接和缩略图的滑块,如下所示:

    <li id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <a href="<?php echo the_permalink(); ?>" class="listing-link">
            <?php
            if ( true == $thumbnail ) {
                // if the post has a feature image, show it.
                if ( has_post_thumbnail() ) {
                    the_post_thumbnail( $thumbsize );
                // else if the post has a mime type that starts with "image/" then show the image directly.
                } elseif ( 'image/' == substr( $post->post_mime_type, 0, 6 ) ) {
                    echo wp_get_attachment_image( $post->ID, $thumbsize );
                }
            }
            ?>
            <div class="title">
                <?php the_title(); ?>
            </div>
        </a>
    </li>

使用Wordpress Codex和来自this related post的提示,我已经正确地更改缩略图下方的标题,但我似乎无法在<a href=""条上找到正确的组合调用缩略图的类别URL。有没有办法正确地做到这一点?这就是我现在所处的位置:

    <li id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <a href="<?php $categories = get_categories(); foreach ($categories as $cat) { $category_link = get_category_link($cat->cat_ID); } echo esc_url( $category_link ); ?>" class="home-category-link">
            <?php
            if ( true == $thumbnail ) {
                // if the post has a feature image, show it.
                if ( has_post_thumbnail() ) {
                    the_post_thumbnail( $thumbsize );
                // else if the post has a mime type that starts with "image/" then show the image directly.
                } elseif ( 'image/' == substr( $post->post_mime_type, 0, 6 ) ) {
                    echo wp_get_attachment_image( $post->ID, $thumbsize );
                }
            }
            ?>
            <div class="title">
                <?php the_category(); ?>
            </div>
        </a>
    </li>

这是我得到的最接近的,但是网址现在提取与帖子无关的类别网址。不知道我错过了什么,但任何帮助表示赞赏。谢谢!

0 个答案:

没有答案