在WordPress中给推荐文章添加缩略图

前端之家收集整理的这篇文章主要介绍了在WordPress中给推荐文章添加缩略图前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

对于如何在wordpress显示推荐文章,网上有非常多方法,但似乎不是那么令人满意。在本教程中,我们将与大家分享一种可以让用户选择某些特定文章并通过使用wordpress2.9新增的缩略图功能显示这些文章方法。此方法可以避免使用“置顶文章”,在其他一些自定义方法中由于其他功能不可避免要使用到“置顶文章”。

注意: 使用本教程需要熟悉一些wordpressPHP、HTML和CSS知识。

我们修改了由W3C Gallery公司San制作的Featured Posts Lists插件。虽然San给这款插件创建了一个高级版本可以显示图片,但它需要一个自定义字段。这样一来,你只能在2.9中使用这个缩略图功能

最终效果

PHPky/www.w3cgallery.com/w3c-css/display-specificmultiple-posts-as-featured-post-list-plugins
Description: Display specific/multiple posts List with Thumbnails on your sidebar or any place of your site. It creates a tab "Featured Posts List" in "Settings" tab
Version: 2.0
Author: SAN – w3cgallery.com & Windowshostingpoint.com & Syed Balkhi
Author URI: http://www.w3cgallery.com/
*/

// Main function to diplay on front end

function featuredpostsList() {
global $post,$wpdb,$posts_settings;
// posts_id from database
$posts_id = $posts_settings['posts_id'];

if($posts_id) {

$posts_idarray = explode(',',$posts_id);

foreach ($posts_idarray as $list){
$post = new WP_Query('p='.$list.'');
$post->the_post();
?>
<div class="popcontainer">
<div class="popthumb"><a href="<?PHP the_permalink(); ?>" title="<?PHP the_title(); ?>"><?PHP the_post_thumbnail(); ?></a></div>
<div class="popcontent">
<h2><a href="<?PHP the_permalink() ?>" rel="bookmark"><?PHP the_title(); ?></a></h2>
<div class="popauthor"><?PHP the_time('M j,Y') ?></div>

</div>

</div>

<?PHP }
} else {
echo $before ."None found". $after;
}
}

$data = array(
'posts_id' => ''
);
$ol_flash = '';

$posts_settings = get_option('posts_settings');

// ADMIN PANLE SEETTING
function posts_add_pages() {
// Add new menu in Setting or Options tab:
add_options_page('Featured Posts List','Featured Posts List',8,'postsoptions','posts_options_page');
}

/* Define Constants and variables*/
define('PLUGIN_URI',get_option('siteurl').'/wp-content/plugins/');

/* Functions */

function posts_options_page() {
global $ol_flash,$posts_settings,$_POST,$wp_rewrite;
if (isset($_POST['posts_id'])) {
$posts_settings['posts_id'] = $_POST['posts_id'];
update_option('posts_settings',$posts_settings);
$ol_flash = "Your Featured List has been saved.";
}

if ($ol_flash != '') echo '<div id="message"class="updated fade"><p>' . $ol_flash . '</p></div>';

echo '<div class="wrap">';
echo '<h2>Add Posts ID to Create Featured Post List</h2>';
echo '<table class="optiontable form-table"><form action="" method="post">
<tr><td colspan="2"><strong>This plugin gives full freedom to display multiple posts as Featured Post List to your site.</strong></td></tr>
<tr><td><strong>Post ID :</strong></td><td><input type="text" name="posts_id" value="' . htmlentities($posts_settings['posts_id']) . '" size="50%" /></td></tr>
<tr><td colspan="2"><strong>SAN Hint: To Add Multiple Post IDs use "," for exmple : " 1,2,3" </strong></td></tr>
</table>';

echo '<Div class="submit"><input type="submit" value="Save your list" /></div>
<p>Paste this code into where you want it to display featured posts list <strong>&lt;?PHP featuredpostsList(); ?&gt;</strong> <br/> Or you can pass variable before and after like this default setting <strong>&lt;?PHP featuredpostsList($before = &lt;li&gt;",$after = &lt;/li&gt;") ?&gt;</strong></p>
</form>';
echo '</div>';

}

add_action('admin_menu','posts_add_pages');

?>

 完成后,你可以在模板文件的任何地方粘贴该代码即可。

<?PHP featuredpostsList(); ?>

猜你在找的wordpress相关文章