php - Wordpress - 每个特色图片都有不同的自定义链接

标签 php html wordpress

我是 Stack overflow 的新手。 首先感谢所有社区接受我的订阅。 我正在构建的网站有一个小问题:

http://gianfabiopezzolla.com/centocelleonline.it

在头版,我有一个 Mansory,用于显示特色图片和标题的最新帖子。

我想为每个特色图片设置一个指向不同页面的自定义链接(例如,第一张特色图片 -> 联系页面)。

我试过下面的代码,但似乎不起作用:

<article id="post-<?php the_ID(the_id_of_post); ?>" <?php post_class(); ?>>
<div class="item-sizer">
    <?php if ( has_post_thumbnail() && ( get_theme_mod( 'index_feat_image' ) != 1 ) ) : ?>
        <div class="entry-thumb">
            <a href="<?php the_permalink(the_id_of_page); ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail('oria-small-thumb'); ?></a>        
        </div>
    <?php endif; ?>

    <header class="entry-header blog-entry-header">
        <?php the_title( sprintf( '<h1 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink(the_id_of_page) ) ), '</a></h1>' ); ?>
    </header><!-- .entry-header -->

</div>
</article><!-- #post-## -->

有人可以帮助我吗?

最佳答案

我认为如果你像这样使用 get_permalink 就可以了

$link = get_the_permalink($page_id); 
<div class="entry-thumb">
<a href="<?php echo $link; ?>"> title="<?php the_title(); ?>"><?php the_post_thumbnail('oria-small-thumb'); ?></a>        
</div>

其中 $page_id 是您想要的页面的 ID 是因为 the_permalink(); 直接回显了

get_permalink();

将返回一个您必须手动回显的值。这就是您的链接未被打印的原因。

希望对您有所帮助,请尝试一下。

关于php - Wordpress - 每个特色图片都有不同的自定义链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36197345/

相关文章:

html - 如何将我的图像居中对齐到 div 中?

html - 当水平菜单太大时如何让水平菜单向左移动

mysql - WordPress 自定义帖子类型中的可重复多列数据行

html - 为什么 "&#8203;"被注入(inject)到我的 HTML 中?

php - 应用于购物车的购物车折扣在 wordpress 中使用 Woocommerce 时未在订单总计中显示正确的金额

javascript - ShareThis WP 插件 - 禁用 onhover?

php - 从 php 调用嵌套存储过程

php - 如何将两个不同的排名重定向到同一页面

PHP : is there any function works like xmlrpc_encode_request?

php - 如何检测是否必须对字符串应用 UTF-8 解码或编码?