Un article pour tester l’insertion de code

On parlera une autre fois de comment intégrer highlight.js dans wordpress (sans plugin bien sûr). C’est très simple.
Voici du css :
/*
* Dropdwon menu feature specific css rules
*
* sources :
* http://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_js_dropdown_hover
* http://cssdeck.com/labs/another-simple-css3-dropdown-menu
*
*/
.menu-item-has-children
{
position: relative;
}
.sub-menu
{
display: none;
position: absolute;
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
white-space: nowrap; /* To avoid line feed between words */
}
.sub-menu a
{
color: black;
padding: 10px 14px;
text-decoration: none;
display: block;
}
.sub-menu li
{
float: none;
}
.sub-menu a:hover
{
background-color: #f1f1f1
}
.menu-item-has-children:hover .sub-menu
{
display: block;
}
.menu-item-has-children:hover > a {
background-color: #f9f9f9;
}
Et du javascript :
jQuery( document ).ready( function($)
{
// update, ajaxurl, post and token are member of data array defined using wp_localize_script when enqueuing the script in popular.php
// use GET method as it is a little more efficient than POST and this one is not needed here
// popular_update action must be called only if update == true (ie : from single post or page)
if( data.update == true )
{
jQuery.get
(
data.ajaxurl,
{
'action': 'popular_update',
'id': data.post.ID,
'token' : data.token,
},
function(response)
{
//console.log(response);
$('.popular-count').html(response);
}
);
}
jQuery.get
(
data.ajaxurl,
{
'action': 'popular_list',
},
function(response)
{
//console.log(response);
$('.popular-list').html(response);
}
);
} );
Du HTML :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Table layout test</title>
<link rel="stylesheet" href="normalize.css">
<link rel="stylesheet" href="html5blank.css">
<link rel="stylesheet" href="table.css">
</head>
<body>
<header class="headline">
<span class="title">En ce moment</span>
<div class="content">
<ul id="newsticker">
<li><a href="#">texte cellule 2.0</a></li>
<li><a href="#">texte cellule 2.1</a></li>
<li><a href="#">texte cellule 2.2</a></li>
<li><a href="#">texte cellule 2.3</a></li>
<li><a href="#">texte cellule 2.4</a></li>
<li><a href="#">texte cellule 2.5</a></li>
<li><a href="#">texte cellule 2.6</a></li>
<li><a href="#">texte cellule 2.7</a></li>
<li><a href="#">texte cellule 2.8</a></li>
<li><a href="#">texte cellule 2.9</a></li>
</ul>
</div>
<form class="search">
<input type=search" class="input"/>
<button type="submit" class="submit"><span>Search</span></button>
</form>
</header>
</body>
</html>
Du php :
function djth_non_duplicate_content( $wp )
{
global $wp_query;
// if user try to navigate to a category
if( isset( $wp_query->query_vars['category_name'], $wp_query->query['category_name'] ) )
{
global $wp_rewrite;
$paged = isset( $wp_query->query_vars['paged'] ) && (int)$wp_query->query_vars['paged']>1 ? '/'.$wp_rewrite->pagination_base.'/'.(int)$wp_query->query_vars['paged'] : '';
// Retrieve asked category URL and current URL
$correct_url = get_term_link( $wp_query->query_vars['category_name'], 'category' );
if( is_string( $correct_url ) && $correct_url )
{
$correct_url .= $paged;
}
$actual_url = home_url( $_SERVER['REQUEST_URI'] );
// If different URL, redirect to the right category URL
if( is_string( $correct_url ) && $correct_url != $actual_url )
{
wp_redirect( $correct_url, 301 );
die();
}
}
}
Un peu de SQL pour finir (et une petite mise en abîme 🙂 :
UPDATE wp_posts SET post_content = REPLACE(post_content, '<pre lang="BASH" line="1">', '</code></pre>')
WHERE post_content LIKE '%<pre lang="BASH" line="1">%';