普通网友 2012-10-08 13:26
浏览 44
已采纳

如何在php中创建wordpress固定链接[关闭]

I have a php page where I am getting latest blog posts from db like this

$result = mysql_query("SELECT * FROM wp_posts ORDER BY ID DESC LIMIT 3")ordie(mysql_error());

Now from here I want to redirect to actual wordpress post

<a href="#" target="_blank"><?php echo $row->post_title; ?></a>

How do I get the permalink? any help? thanks in advance

  • 写回答

2条回答 默认 最新

  • dougang5088 2012-10-08 13:32
    关注

    Wordpress generates your URLs instead of storing them,

    try this query from Dave Heavy Industries

    SELECT wpp.post_title, wpp.guid, wpp.post_date, CONCAT(wpo_su.option_value, REPLACE( REPLACE( REPLACE( REPLACE(wpo.option_value,'%year%',date_format(wpp.post_date,'%Y')) ,'%monthnum%',date_format(wpp.post_date,'%m')) ,'%day%',date_format(wpp.post_date,'%d')) ,'%postname%',wpp.post_name ) ) as permalink FROM wp_posts wpp INNER JOIN wp_options wpo on wpo.option_name='permalink_structure' and wpo.blog_id=0 INNER JOIN wp_options wpo_su on wpo_su.option_name='siteurl' and wpo_su.blog_id=wpo.blog_id WHERE wpp.post_type = 'post' AND wpp.post_status = 'publish' ORDER BY wpp.post_date DESC 
    

    then you can get the link like

    <a href="<?php echo $row->permalink; ?>" target="_blank"><?php echo $row->post_title; ?></a>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 统计大规模图中的完全子图问题
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题