Php Wordpress帖子,链接到分类页面
在此wordpress功能中:Php Wordpress帖子,链接到分类页面,php,wordpress,Php,Wordpress,在此wordpress功能中: function ct_post_nav() { ?> <ul> <li class="post-nav-all"> <?php $linktitelposts = get_cat_ID( $cat_name ); if ($linktitelposts == 'blogs' )
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 -->
函数ct\u post\u nav(){?>
-
我想要一个链接回到li中的分类页面。那里的php行现在是我尝试过的,但它当然不起作用。有没有办法获得每个类别都会更改的链接?试试这个和
函数ruls Isreturn
或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>';
}
}
?>
尝试此操作,然后函数
规则为返回
或回显
值
<?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>';
}
}
?>
谢谢你的回答,我尝试了类似的方法。但它只链接回同一篇文章。如果我使用你的版本,它会使网站崩溃。@bhaveshvala函数需要$cat\u name
参数,所以它应该像函数ct\u post\u nav($cat\u name){
我尝试了您的更改,我也将href更改为实际页面,在博客页面上它可以工作,但在另一个页面上它保持相同的链接。好的,谢谢您的回答,我尝试了类似的方法。但它只链接回同一篇文章。如果我使用您的版本,它会使网站崩溃。@bhaveshvala函数需要$cat\u name
参数,因此它应该像函数ct\u post\u nav($cat\u name){
我尝试了您的更改,我也将href更改为实际页面,在博客页面上它工作,但在不同页面上它保持相同的链接。好的,使用var\u dump($cat\u name)中的内容
?此$cat\u name
在何处定义?您在变量转储($cat\u name)
中得到了什么?此$cat\u name
在何处定义?