-
-
Save fernandopetry/3991c88484b4aa49bb9b to your computer and use it in GitHub Desktop.
WORDPRESS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How to add a widget area to your theme. | |
<div id="sidebar"> | |
<ul> | |
<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar()) : ?> | |
<li><!-- stuff shown here in case no widgets active --></li> | |
<?php endif; ?> | |
</ul> | |
</div> | |
Now in your functions.php file, you “register” the sidebar with a custom function: | |
if (function_exists('register_sidebar')) { | |
register_sidebar(array( | |
'before_widget' => '<li id="%1$s" class="widget %2$s">', | |
'after_widget' => '</li>', | |
'before_title' => '<h2 class="widgettitle">', | |
'after_title' => '</h2>', | |
)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php /* Template Name: Archives */ ?> | |
<?php get_header(); ?> | |
<div id="content"> | |
<h2> | |
<?php the_title(); ?> | |
</h2> | |
<div class="col"> | |
<h3>Archives by Year:</h3> | |
<ul> | |
<?php wp_get_archives('type=yearly'); ?> | |
</ul> | |
<h3>Archives by Month:</h3> | |
<ul> | |
<?php wp_get_archives('type=monthly'); ?> | |
</ul> | |
<h3>Archives by Day:</h3> | |
<ul> | |
<?php wp_get_archives('type=daily'); ?> | |
</ul> | |
<h3>Archives by Category:</h3> | |
<ul> | |
<?php wp_list_categories('title_li='); ?> | |
</ul> | |
<h3>Archives by Author:</h3> | |
<ul> | |
<?php wp_list_authors(); ?> | |
</ul> | |
</div> | |
<div class="col"> | |
<h3>All Pages:</h3> | |
<ul> | |
<?php wp_list_pages('title_li='); ?> | |
</ul> | |
<h3>Archives by Tag:</h3> | |
<?php wp_tag_cloud(); ?> | |
</div> | |
</div> | |
<?php get_sidebar(); ?> | |
<?php get_footer(); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if (is_page_template("page-snippet.php")){ ?> | |
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory'); ?>/css/snippets.css" /> | |
<?php } ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Display list of Links. These are just a few example parameters, see the Codex at http://digwp.com/u/32. | |
<?php wp_list_bookmarks(array( | |
'orderby' => 'name', // alphabetical | |
'order' => 'ASC', // starting at A | |
'limit' => -1, // unlimited, show ALL bookmarks | |
'title_li' => __('Bookmarks'), // include list item title | |
'title_before' => '<h2>', // tag before title | |
'title_after' => '</h2>', // tag after title | |
)); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add jquery to theme. | |
Put this PHP code into your functions.php file. This will load the jQuery library onto your page by inserting a link in the <head> section where you call wp_head. | |
<?php | |
if(!is_admin()) { | |
wp_deregister_script('jquery'); | |
wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"), false, '1.3.2'); | |
wp_enqueue_script('jquery'); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Display a list of categories. These are just a few example parameters, see the Codex at http://digwp.com/u/31. | |
<?php wp_list_categories(array( | |
'orderby' => 'name', // alphabetical | |
'order' => 'ASC', // starting at A | |
'show_count' => 0, // do NOT show # of posts per cat | |
'title_li' => __('Categories'), // include title list item | |
'exclude' => 12, // ID of category to exclude | |
'depth' => 0 // levels deep to go down cat tree | |
)); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // display recent comments function.php code | |
function dp_recent_comments($no_comments = 10, $comment_len = 35) { | |
global $wpdb; | |
$request = "SELECT * FROM $wpdb->comments"; | |
$request .= " JOIN $wpdb->posts ON ID = comment_post_ID"; | |
$request .= " WHERE comment_approved = '1' AND post_status = 'publish' AND post_password =''"; | |
$request .= " ORDER BY comment_date DESC LIMIT $no_comments"; | |
$comments = $wpdb->get_results($request); | |
if ($comments) { | |
foreach ($comments as $comment) { | |
ob_start(); ?> | |
<li> <a href="<?php echo get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID; ?>"><?php echo dp_get_author($comment); ?>:</a> <?php echo strip_tags(substr(apply_filters('get_comment_text', $comment->comment_content), 0, $comment_len)); ?> </li> | |
<?php ob_end_flush(); | |
} | |
} else { | |
echo '<li>No Comments</li>'; | |
} | |
} | |
function dp_get_author($comment) { | |
$author = ""; | |
if ( empty($comment->comment_author) ) | |
$author = 'Anonymous'; | |
else | |
$author = $comment->comment_author; | |
return $author; | |
} ?> | |
To use this function, simply call it from anywhere in your theme: | |
<?php dp_recent_comments(6); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This will output a list of linked Post titles according to the specified parameters. | |
<?php wp_get_archives(array( | |
'type' => 'postbypost', // or daily, weekly, monthly, yearly | |
'limit' => 10, // maximum number shown | |
'format' => 'html', // or select (dropdown), link, or custom | |
'show_post_count' => false, // show number of posts per link | |
'echo' => 1 // display results or return array | |
)); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Display a tag cloud. These are just a few example parameters, see the Codex at http://digwp.com/u/30. | |
<?php wp_tag_cloud(array( | |
'smallest' => 10, // size of least used tag | |
'largest' => 18, // size of most used tag | |
'unit' => 'px', // unit for sizing | |
'orderby' => 'name', // alphabetical | |
'order' => 'ASC', // starting at A | |
'exclude' => 6 // ID of tag to exclude from list | |
)); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment