Skip to content

Instantly share code, notes, and snippets.

@anatol06
anatol06 / index.php
Last active May 7, 2018 18:33
WP - Meta List
<ul class="meta">
<li>By
<a href="<?php echo get_author_posts_url(get_the_author_meta('ID')); ?>">
<?php the_author(); ?></a>
</li>
<li><?php the_time('F j, Y g:i a'); ?></li>
<li>
<?php
$categories = get_the_category();
$separator = ", ";
@anatol06
anatol06 / single.php
Last active May 4, 2018 19:31
WP - Insert Sidebar
<?php if(is_active_sidebar('sidebar')) : ?>
<?php dynamic_sidebar('sidebar'); ?>
<?php endif; ?>
@anatol06
anatol06 / index.php
Created May 6, 2018 16:11
Link to the author posts by ID
<a href="<?php echo get_author_posts_url( get_the_author_meta('ID')); ?>"><?php the_author(); ?></a>
@anatol06
anatol06 / index.php
Last active May 6, 2018 16:20
Get posts except specified cathegory
<?php // Get all posts except Featured
$no_featured_query = new WP_Query(array(
'cat' => '-3',
)); ?>
<?php while($no_featured_query->have_posts()) : ?>
<?php $no_featured_query->the_post(); ?>
<!-- HTML here-->
@anatol06
anatol06 / front-page.php
Last active May 6, 2018 16:20
Get a featured query with each even post floated Right
<?php
$i = 0; // Counter
?>
<?php $featured_query = new WP_query(array(
'category_name' => 'featured' )); ?>
<?php while ($featured_query->have_posts()) :
$featured_query->the_post(); ?>
@anatol06
anatol06 / front-page.php
Created May 6, 2018 16:24
The time in format - MAY 6, 2018 2:47 PM
<?php the_time('F j, Y g:i a'); ?>
@anatol06
anatol06 / index.php
Last active May 6, 2018 21:53
Get the list of categories to which the article belongs
<?php // Get the list of categories to which the article belongs
$categories = get_the_category();
$separator = ", ";
$output = '';
if($categories) {
foreach($categories as $category) {
$output .= '<a href="'.
get_category_link($category->term_id).'">'.
@anatol06
anatol06 / archive.php
Last active May 6, 2018 16:53
Get the title for Archive or Search pages
<!-- Get Archive Title -->
<?php if(is_category()) {
single_cat_title();
} else if (is_author()) {
the_post();
echo 'Archives By Author: ' .get_the_author();
rewind_posts();
} else if (is_tag()) {
single_tag_title();
@anatol06
anatol06 / functions.php
Created May 6, 2018 18:16
Regeister and init Sidebar and 4 footer widgets
// Widget Locations
function fc_init_widgets($id){
register_sidebar(array(
'name' => 'Sidebar',
'id' => 'sidebar',
'before_widget' => '<div class="sidebar-widget">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
@anatol06
anatol06 / footer.php
Last active May 6, 2018 21:53
Insert the Widget in template