Skip to content

Instantly share code, notes, and snippets.

@eversthomas
Last active November 4, 2019 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eversthomas/d547095d0a12f6ae2fb975dbd40d5097 to your computer and use it in GitHub Desktop.
Save eversthomas/d547095d0a12f6ae2fb975dbd40d5097 to your computer and use it in GitHub Desktop.
wordpress functions and explainings
<?php
// register sidebar widgets
function iatmul_widgets_init() {
// footer widgets
$footer_sidebar_number = 3; //Number of footer sidebars
for( $i=1; $i <= $footer_sidebar_number; $i++ ) {
register_sidebar( array(
'name' => sprintf( __( 'Footer Area %d', 'iatmul' ), $i ),
'id' => sprintf( 'footer-%d', $i ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
'description' => sprintf( __( 'Footer %d widget area.', 'iatmul' ), $i ),
) );
}
}
add_action( 'widgets_init', 'iatmul_widgets_init' );
<section>
<?php
// more info on https://developer.wordpress.org/reference/classes/wp_query/
// get the latest 3 posts, but withour the posts taged with 'sticky_posts'
$args = array(
'post_type' => 'post',
'posts_per_page' => '3',
'post__not_in' => get_option("sticky_posts")
);
$latest_posts = new WP_Query($args);
if ( $latest_posts->have_posts() ) : while ( $latest_posts->have_posts() ) : $latest_posts->the_post(); ?>
<?php get_template_part( 'template-parts/content' ); ?>
<?php endwhile; else : ?>
<?php get_template_part( 'template-parts/content', 'none' ); ?>
<?php endif; wp_reset_postdata(); ?>
</section>
<?php
$post = get_post( 1875 ); // to get one single post or page by its ID (1875 in example)
$output = apply_filters( 'the_content', $post->post_content );
echo $output;
?>
<?php
if ( have_posts() ) : // are there any posts or pages???
the_archive_title( '<h1 class="page-title">', '</h1>' );
// Start the loop.
while ( have_posts() ) : // count every post or page you find
the_post(); // for all the metadata of the posts and pages
?><a href="<?php the_permalink(); ?>"><?php the_title( '<h3>', '</h3>' ); ?></a><?php // the post or page title with link to post or page
the_post_thumbnail(); // show post thumbnail
the_content(); // show full post or page content
the_content('Read the rest of this entry &raquo;'); // the content with readmore link
the_author(); // show the author
the_date( 'd-m-Y' ); // show the post date (day, mounth, year)
the_category(); // show the category the post belong to
the_meta(); // show meta data of the post
the_tags(); // show the post tags
next_posts_link( 'Older Entries', $the_query->max_num_pages ); // the next post
previous_posts_link( 'Newer Entries' ); // the previous post
endwhile;
the_posts_pagination(); // a pagination of the posts sites
else : // when there are no posts or pages show:
_e("Sorry, but you are looking for something that isn't here."); // show this sentence, if there are no posts
endif;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment