PROJET AUTOBLOG


benimarine

Site original : benimarine

⇐ retour index

Mise à jour

Mise à jour de la base de données, veuillez patienter...

Facebook Integration for WordPress

samedi 8 juin 2013 à 17:56

Starting today WordPress publishers can easily integrate Facebook features, such as social publishing and mentions, through the new Facebook for WordPress plugin.

The plugin was built by Facebook engineers in collaboration with open source partners, and makes it simple for anyone to make their WordPress site more social – no coding required. The plugin will also work on mobile and support internationalization.

Social Publishing

Once the plugin is installed, you can cross-post content published to WordPress to your Facebook Timeline and the Facebook Pages you manage. You can also mention the names of Pages and friends as you post to further distribute your content.

WordPress Widgets

The following social plugins are available as WordPress widgets:

  • Activity Feed: Shows readers their friends’ activity on the site, such as likes and comments.
  • Recommendations: Gives readers personalized suggestions for pages on your site they might like, as well as a Recommendations Bar option to give users the option to add content to their Timeline as they read.
  • Customizable Like, Subscribe and Send buttons.
  • Comments Box: Makes it easy for people to comment on your site and post back to Facebook, and includes moderation tools. The plugin also features automatic SEO support for Facebook Comments, so search engines can index them to improve your site’s visibility.

TechCrunch, Buzz Media and The Next Web are already using the plugin to connect with their audiences while providing users with more engaging and personalized experiences. The plugin is available for all sites on WordPress.com VIP as well.

WordPress powers 16.6 percent of the web, from The New York Times to People Magazine, and attracts more than 600 million unique visitors each month. We hope the plugin makes it possible for WordPress content to be shared even more widely among people.

Learn more or download the plugin now.


Query or show a specific post in wordpress

samedi 8 juin 2013 à 17:53

If you are looking for php code or a plugin for your WordPress that takes a post ID and returns the database record for that post then read on. This is very helpful when you want to show a specific post on your homepage or other pages to get more attention. It allows you to design your homepage or a page with the post(s) that you want to be shown on the page rather than the 10 recent posts that the WordPress automatically chooses for you.

PHP Code Example to Query a WordPress Post

Example 1

The following code will Query the post with post id 26 and Show the title and the content.

<?php
$post_id = 26;
$queried_post = get_post($post_id);
$title = $queried_post->post_title;
echo $title;
echo $queried_post->post_content;
?>

Example 2

The following style could be more useful as it lets the user customise the font easily.

<?php
$post_id = 26;
$queried_post = get_post($post_id);
?>
<h2><?php echo $queried_post->post_title; ?></h2>
<?php echo $queried_post->post_content; ?>

Example 3

Using an Array… The following code will query every post number in ‘thePostIdArray’ and show the title of those posts.

<?php $thePostIdArray = array("28","74", "82", "92"); ?>
<?php $limit = 4 ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); $counter++; ?>
<?php if ( $counter < $limit + 1 ): ?>
<div id="post-<?php the_ID(); ?>">
<?php $post_id = $thePostIdArray[$counter-1]; ?>
<?php $queried_post = get_post($post_id); ?>
<h2><?php echo $queried_post->post_title; ?></h2>
</div>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>

How to Display the Post Content Like WordPress

When you retrieve the post content from the database you get the unfiltered content. If you want to achieve the same output like WordPress does in its’ posts or pages then you need to apply filter to the content. You can use the following code:

<?php
$post_id = 26;
$queried_post = get_post($post_id);
$content = $queried_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]&gt;', $content);
echo $content;
?>

For a range of all the returned fields that you can use, check the WordPress site here.

Query X Number of Recent Posts

You can use the “wp_get_recent_posts” function to retrieve X number of recent posts and then display them however you want to. Here is an example:

<?php
//Query 5 recent published post in descending order
$args = array( 'numberposts' => '5', 'order' => 'DESC','post_status' => 'publish' );
$recent_posts = wp_get_recent_posts( $args );
//Now lets do something with these posts
foreach( $recent_posts as $recent )
{
    echo 'Post ID: '.$recent["ID"];
    echo 'Post URL: '.get_permalink($recent["ID"]);
    echo 'Post Title: '.$recent["post_title"];
    //Do whatever else you please with this WordPress post
}
?>

Using a Plugin to List all Posts Alphabetically

You can also use the WP Alphabetic Listing WordPress plugin to list all your posts.


Post on your WordPress blog using PHP

samedi 8 juin 2013 à 17:52

Here is the function. This code is not made for being used within WordPress, so don’t paste it on your functions.php file (or any other).

Please note that you must activate the XMLRPC posting option in your WordPress blog. If this option isn’t activated, the code will not be able to insert anything into your blog database. Another thing, make sure the XMLRPC functions are activated on your php.ini file.

function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$category,$keywords='',$encoding='UTF-8') {
    $title = htmlentities($title,ENT_NOQUOTES,$encoding);
    $keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);

    $content = array(
        'title'=>$title,
        'description'=>$body,
        'mt_allow_comments'=>0,  // 1 to allow comments
        'mt_allow_pings'=>0,  // 1 to allow trackbacks
        'post_type'=>'post',
        'mt_keywords'=>$keywords,
        'categories'=>array($category)
    );
    $params = array(0,$username,$password,$content,true);
    $request = xmlrpc_encode_request('metaWeblog.newPost',$params);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
    curl_setopt($ch, CURLOPT_URL, $rpcurl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 1);
    $results = curl_exec($ch);
    curl_close($ch);
    return $results;
?>

WordPress $post Object Quick Reference

samedi 8 juin 2013 à 17:51

How to use the $post object

The values in the chart below can be accessed for a given post within the loop using the following syntax:

?
1
$post->$key;

…where key is the property you want to access below. For example, you’ll notice at the top of this post is a post summary within a formatted div element. The summary is just a formatted version of the post excerpt, but if there’s no post excerpt I don’t want that div element showing up empty, so in that case, I hide it using the following code:

?
1
2
3
4
5
6
7
8
<?php
if($post->post_excerpt != '') :
    echo '<div id="summary">';
    echo '<strong>Summary:</strong><br />';
    the_excerpt();
    echo '</div>';
endif;
?>

$post Object properties

Property Sample Value Notes
post_author 1 Post author’s user number
post_date 2008-03-15 19:22:29
post_date_gmt 2008-03-16 02:22:29 GMT = Greenwich Mean Time
post_content Actual post content, including markup
post_title Post title
post_category 0 Number representing post category ID#
post_excerpt Plain text without markup
post_status publish, pending, draft, private, inherit Current status of the post
comment_status open Possible values: open / closed
ping_status open open / closed
post_password Will be empty if no password
post_name statistics Same as post slug
to_ping http://www.1to-ping.com, http://www.2to-ping.com, http://www.3to-ping.com List of urls to ping when post is published (for unpublished posts)
pinged http://www.pinged1.com, http://www.pinged2.com, http://www.pinged3.com List of urls that have been pinged (for published posts)
post_modified 2008-07-01 19:41:28 Date the post was last modified
post_modified_gmt 2008-07-02 02:41:28 GMT date post was last modified
post_content_filtered Exists to store a cached version of post content (most likely with all the the_content filters already applied). If you’ve got a plugin that runs a very resource heavy filter on content, you might consider caching the results with post_content_filtered, and calling that from the front end instead.
post_parent ID# of this post’s parent. In the case of attachments, will be the post it’s attached to. Defaults to 0 if no parent.
guid http://www.blogurl/postslug Global Unique Identifier. The “real” URL to the post, not the permalink version. For pages, this is the actual URL. In the case of files (attachments), this holds the URL to the file.
menu_order 0
1
2
etc…
Holds values for display order of pages. Only works with pages, not posts.
post_type page
post
attachment
revision
Self-explanatory for pages and posts. Any files uploaded are attachments and post revisions saved as revision
post_mime_type text/html
image/png
image/jpg
Only used for files (attachments). Contains the MIME type of the uploaded file.
comment_count 4 Number of comments, pings, and trackbacks combined

Thanks to everyone who commented on this post to help fill in some of the missing values!


Function Reference/get post

samedi 8 juin 2013 à 17:50

Description

Takes a post ID and returns the database record for that post. You can specify, by means of the $output parameter, how you would like the results returned.

Usage

<?php get_post$id$output$filter ); ?> 

Parameters

$id
(integer or object) (optional) The ID of the post you’d like to fetch, or an object that specifies the post. By default the current post is fetched.
Default: null
$output
(string) (optional) How you’d like the result.

  • OBJECT – (default) returns a WP_Post object
  • ARRAY_A – Returns an associative array of field names to values
  • ARRAY_N – returns a numeric array of field values
Default: OBJECT
$filter
(string) (optional) Filter the post.

  • raw – (default)
Default: raw

Example

To get the title for a post with ID 7:

<?php
$post_7 
get_post(7);
$title $post_7->post_title;
?> 

Alternatively, specify the $output parameter:

<?php
$post_7 
get_post(7ARRAY_A);
$title $post_7['post_title'];
?> 

Return

Returns a WP_Post object, or null on failure.

The fields returned are:

ID 
(integer) The post ID
post_author 
(integer) The post author’s ID
post_date 
(string) The datetime of the post (YYYY-MM-DD HH:MM:SS)
post_date_gmt 
(string) The GMT datetime of the post (YYYY-MM-DD HH:MM:SS)
post_content 
(string) The post’s contents
post_title 
(string) The post’s title
post_category 
(integer) The post category’s ID. Note that this will always be 0 (zero) from wordpress 2.1 onwards. To determine a post’s category or categories, use get_the_category().
post_excerpt 
(string) The post excerpt
post_status 
(string) The post status (publish|pending|draft|private|static|object|attachment|inherit|future|trash)
comment_status 
(string) The comment status (open|closed|registered_only)
ping_status 
(string) The pingback/trackback status (open|closed)
post_password 
(string) The post password
post_name 
(string) The post’s URL slug
to_ping 
(string) URLs to be pinged
pinged 
(string) URLs already pinged
post_modified 
(string) The last modified datetime of the post (YYYY-MM-DD HH:MM:SS)
post_modified_gmt 
(string) The last modified GMT datetime of the post (YYYY-MM-DD HH:MM:SS)
post_content_filtered 
(string)
post_parent 
(integer) The parent post’s ID (for attachments, etc)
guid 
(string) A link to the post. Note: One cannot rely upon the GUID to be the permalink (as it was previous to version 2.5), Nor can you expect it to be a valid link to the post. It’s merely a unique identifier, which so happens to be a link to the post at present.
menu_order 
(integer)
post_type 
(string) (post|page|attachment)
post_mime_type 
(string) Mime Type (for attachments, etc)
comment_count 
(integer) Number of comments

Notes

Before version 3.5, the first parameter $post was required to be a variable. For example, get_post(7) would cause a fatal error.

Source File

get_post() is located in wp-includes/post.php and wp-includes/class-wp-atom-server.php.