簡體   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