我试图将WordPress中的帖子链接到Tumblr上的关联帖子。我将Tumblr id设置为每个WordPress帖子中自定义字段的值。
这是对我有意义的,但链接不是捕获或输出值:
<h3><a href="http://xxx.tumblr.com/post/<?php $key="mykey"; echo get_post_meta($post->ID, tumblr_id, true); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'hapcam' ), the_title_attribute( 'echo=0' ) ) ); ?>" rel="bookmark" target="_blank"><?php the_title(); ?></a></h3>
以上代码是否有问题,任何人都可以看到?任何帮助一如既往地非常感谢,谢谢!
另外,我使用Ajax加载更多插件将帖子加载到页面,不确定是否为什么......
答案 0 :(得分:0)
元键应该是一个字符串。你没有使用$key
所以我会删除它以避免混淆。
改变这个:
<?php $key="mykey"; echo get_post_meta($post->ID, tumblr_id, true); ?>
要:
<?php echo get_post_meta( $post->ID, 'tumblr_id', true ); ?>
答案 1 :(得分:0)
好的,所以我意识到问题是什么,因为我使用函数将帖子加载到页面,global $post;
需要在循环中声明。
另外,正如@Nathan Dawson所指出的,元数据需要声明为字符串。