简体   繁体   中英

Wordpress posts, link to category pages

Within this wordpress function:

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

I want a link back to the categorie pages inside the li. The php lines that are in there now are what I tried, but of course it does not work. Is there a way to get a link that changes per category?

Try this and function ruls is return or echo value

<?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>';
            }
    }
    ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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