包含帖子标题的自定义文本框

时间:2013-11-29 作者:nino

我在wordpress网站的主页上添加了两个文本框,我只需要显示最近的帖子标题。我应该添加哪行代码来实现这一点?

下面是我用来创建方框的代码:

<p> 
<div class="zedity-editor zedity-notheme" id="zed_fbnvrcpt" style="position: relative; width: 1000px; height: 200px; overflow: hidden;">
<div class="zedity-box zedity-box-Text zedity-edited" style="position: absolute; left: 1px; top: 0px; width: 559px; height: 109px; z-index: 12; display: table; table-layout: fixed; background-color: rgba(242,242,242,1);" data-boxtype="Text">
<div class="zedity-content" style="width: 100%; height: 100%; color: black; font-size: 14px; line-height: 17px; font-family: Arial,Helvetica,sans-serif; display: table-cell; overflow: hidden;">
<p style="margin: 0px; color: black; font-size: 14px; line-height: 17px; font-family: Arial, Helvetica, sans-serif;">Latest News</p>
</div>
<div class="zedity-box zedity-box-Text zedity-edited" style="position: absolute; left: 735px; top: 0px; width: 266px; height: 103px; z-index: 14; display: table; table-layout: fixed; background-color: rgba(110,110,110,1);" data-boxtype="Text">
<div class="zedity-content" style="width: 100%; height: 100%; color: black; font-size: 14px; line-height: 17px; font-family: Arial,Helvetica,sans-serif; display: table-cell; overflow: hidden;">
<p style="margin: 0px; color: black; font-size: 14px; line-height: 17px; font-family: Arial, Helvetica, sans-serif;">Our Clients</p>

</div>
</div>
</div>
</div>

</p> 

1 个回复
SO网友:s_ha_dum

如果你在Google中键入“Wordpress获取最新帖子”,你会看到,就在列表的顶部,wp_get_recent_posts. 按照该链接,您将进入Codex中该函数的“函数引用”页面,在那里,您会发现,大约在一半的时候,有人发布了一个示例,它几乎完全符合您的要求--创建一个帖子标题列表。

<h2>Recent Posts</h2>
<ul>
<?php
    $recent_posts = wp_get_recent_posts();
    foreach( $recent_posts as $recent ){
        echo \'<li><a href="\' . get_permalink($recent["ID"]) . \'" title="Look \'.esc_attr($recent["post_title"]).\'" >\' .   $recent["post_title"].\'</a> </li> \';
    }
?>
</ul>
看起来您刚刚注册,所以在将来,请注意you are expected to have researched the problem and made an attempt at solving it before posting a question.

结束

相关推荐