繁体   English   中英

WordPress帖子,链接到类别页面

[英]Wordpress posts, link to category pages

在此wordpress函数中:

function ct_post_nav() { ?>
        <ul>
           <li class="post-nav-all">
              <?php $linktitelposts = get_cat_ID( $cat_name );          
                 if ($linktitelposts == 'blogs' )
                 {$linktitelposts = '<a href="#">Lees alle blogs</a>';}
                 if ($linktitelposts == 'vacatures')
                 {$linktitelposts = '<a href="#">Lees alle vacatures</a>';}
             ?> 
           </li>
        </ul>
    </div><!-- .nav-links -->
</nav><!-- .navigation -->

我想要一个链接回到li内的类别页面。 我现在尝试了其中的php行,但是当然不起作用。 有没有一种方法可以获取随类别而变化的链接?

试试这个, function规则是return值或echo

<?php function ct_post_nav($cat_name) { 
            // Get the ID of a given category
            $linktitelposts = get_cat_ID( $cat_name );
            // In this variable `$linktitelposts` Your Category ID and Pass this id
            // Get the URL of this category
            $category_link = get_category_link( $linktitelposts );


        <!-- Print a link to this category -->

            if ($linktitelposts == 'blogs' )
            {
             // Not use Same variable `$linktitelposts` 
             echo $anLink = '<a href="<?php echo esc_url( $category_link ); ?>">Lees alle blogs</a>';
            }
            else if ($linktitelposts == 'vacatures')
            {
             // Not use Same variable `$linktitelposts` 
             echo  $anLink = '<a href="<?php echo esc_url( $category_link ); ?>">Lees alle vacatures</a>';
            }
    }
    ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM