Skip to content

Instantly share code, notes, and snippets.

@IN2WEBS IN2WEBS/content.php
Last active Nov 14, 2016

Embed
What would you like to do?
WordPress theme
<article class="post <?php if ( has_post_thumbnail() ) { ?>has-thumbnail <?php } ?>">
<div class="post-thumbnail">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('small-thumbnail'); ?></a>
</div>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_content(); ?>
</article>
<?php
function learningWP() {
wp_enqueue_style('style', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts', 'learningWP');
//Get top ancestor
function get_top_an_id() {
global $post;
if ($post->post_parent) {
$ancestors = array_reverse(get_post_ancestors($post->ID));
return $ancestors[0];
}
return $post->ID;
}
// does page has children?
function has_children() {
global $post;
$pages = get_pages('child_of=' . $post->ID);
return count($pages);
}
// Images
function learningWP_setup() {
// Navigation menu
register_nav_menus(array(
'primary' => __( 'Primary Menu'),
'footer' => __('Footer Menu'),
));
// Add featured image support
add_theme_support('post-thumbnails');
add_image_size('small-thumbnail', 180, 120, true);
add_image_size('banner-image', 920, 210, array('left' , 'bottom'));
}
add_action('after_setup_theme' , 'learningWP_setup');
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo('charset'); ?>">
<meta name="viewport" content="width=device-width">
<title><?php bloginfo('name'); ?></title>
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<div class="container">
<!-- site header-->
<header class="site-header">
<h1><a href="<?php echo home_url(); ?>"><?php bloginfo('name'); ?></a></h1>
<h5><?php bloginfo('description'); ?></h5>
<nav class="site-nav">
<?php
$args = array('theme_location' => 'primary'); ?>
<?php wp_nav_menu( $args ); ?>
</nav>
</header>
<!-- site header-->
<?php
get_header();
if(have_posts()) :
while (have_posts()) : the_post();
get_template_part('content');
endwhile;
else :
echo '<p>No content found</p>';
endif;
get_footer();
?>
<?php
get_header();
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<article class="post page">
<div class="container clearfix">
<div class="title-column">
<h2><?php the_title(); ?></h2>
</div>
<div class="text-column">
<?php the_post_thumbnail(); ?>
<?php the_content(); ?>
</div>
</div>
</article>
<?php endwhile;
else :
echo '<p>No content found</p>';
endif;
get_footer();
?>
<?php
get_header();
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<article class="post page">
<?php
if ( has_children() OR $post->post_parent > 0 ) { ?>
<nav class="site-nav children-links clearfix">
<span class="parent-link"><a href="<?php echo get_the_permalink(get_top_an_id())?>"><?php echo get_the_title(get_top_an_id()); ?></a></span>
<ul>
<?php $args = array(
'child_of' => get_top_an_id(),
'title_li' => ''
); ?>
<?php wp_list_pages($args); ?>
</ul>
</nav>
<?php } ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</article>
<?php endwhile;
else :
echo '<p>No content found</p>';
endif;
get_footer();
?>
<?php
get_header();
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<article class="post">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_post_thumbnail('banner-image'); ?>
<?php the_content(); ?>
</article>
<?php endwhile;
else :
echo '<p>No content found</p>';
endif;
get_footer();
?>
<?php
/*
Template Name: Info Box template
*/
get_header();
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<article class="post page">
<h2><?php the_title(); ?></h2>
<!-- info box-->
<div class="info-box">
<h4>Title</h4>
<p>Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut
fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.</p>
</div>
<?php the_content(); ?>
</article>
<?php endwhile;
else :
echo '<p>No content found</p>';
endif;
get_footer();
?>
/*
Theme Name: wp-theme
Author: RolandK
Author URI: http://www.rolandkwebs.com
Version: 1.0
*/
html {
padding: 0;
margin: 0;
}
body {
padding: 0;
margin: 0;
font-family: Arial, sans-serif;
font-size: 14px;
color: #333;
}
a:link,
a:visited {
color: #006ec3;
}
p {
line-height: 1.65em;
margin: 0 0 1em 0;
}
h1, h2, h3, h4, h5, h6 {
margin: 0 0 1em 0;
font-weight: normal;
}
/* General Layout */
div.container {
max-width: 920px;
margin: 0 auto;
padding-left: 20px;
padding-right: 20px;
}
/* Content Area */
article.post {
border-bottom: 1px dotted #DDD;
margin-bottom: 20px;
}
article.post:last-of-type {
border-bottom: none;
}
/* Header */
.site-header {
border-bottom: 1px solid #DDD;
margin-bottom: 20px;
padding: 30px 0 0 0;
}
.site-header h1 {
margin: 0;
}
.site-header h1 a:link,
.site-header h1 a:visited {
text-decoration: none;
}
.site-header h5 {
margin: 0;
}
/* Standard Nav Menu */
.site-nav ul {
margin: 0;
padding: 0;
}
.site-nav ul:before, .site-nav ul:after { content: ""; display: table; }
.site-nav ul:after { clear: both; }
.site-nav ul { *zoom: 1; }
.site-nav ul li {
list-style: none;
float: left;
}
.site-nav ul li a:link,
.site-nav ul li a:visited {
display: block;
}
/* Header Nav Menu */
.site-header nav {
margin-top: 30px;
}
.site-header nav ul li {
margin-right: 5px;
}
.site-header nav ul li a:link,
.site-header nav ul li a:visited {
padding: 10px 17px;
text-decoration: none;
border: 1px solid #DDD;
border-bottom: none;
}
.site-header nav ul li a:hover {
background-color: #ECECEC;
}
.site-header nav ul li.current-menu-item a:link,
.site-header nav ul li.current-menu-item a:visited,
.site-header nav ul li.current-page-ancestor a:link,
.site-header nav ul li.current-page-ancestor a:visited {
font-weight: bold;
background-color: #006ec3;
color: #FFF;
}
/* Footer */
.site-footer {
margin-top: 30px;
border-top: 1px solid #DDD;
font-size: 84%;
}
/* Footer Nav Menu */
.site-footer nav {
margin: 30px 0 10px 0;
}
.site-footer nav ul li {
margin-right: 10px;
padding-right: 10px;
border-right: 1px solid #DDD;
}
.site-footer nav ul li:last-of-type {
border-right: none;
}
/* Page Layout */
article.page h2 {
font-size: 225%;
margin-bottom: 15px;
}
/* =========== */
/* Clearfix*/
.clearfix:before, .clearfix:after { content:""; display: table; }
.clearfix:after { clear: both; }
.clearfix { *zoom: 1; }
/* Two column layout */
div.title-column {
width: 30%;
float: left;
}
div.text-column {
width: 70%;
float: right;
}
/* Info Box*/
div.info-box {
width: 30%;
float: right;
margin: 0 0 30px 30px;
padding: 20px;
background-color: #EEE;
}
div.info-box h4 {
margin-bottom: 6px;
}
div.info-box p {
font-size: 85%;
}
/* =========== */
/* Children links */
.children-links {
margin-bottom: 20px;
font-size: 80%;
}
.children-links a:link,
.children-links a:visited {
text-decoration: none;
}
.children-links ul {
float: left;
}
.children-links li {
margin-right: 20px;
}
.children-links .parent-link {
float: left;
margin-right: 20px;
padding-right: 20px;
border-right: 1px solid #DDD;
font-size: 120%;
font-weight: bold;
}
.children-links .parent-link a:link,
.children-links .parent-link a:visited {
color: #333333;
}
.children-links .current_page_item a:link,
.children-links .current_page_item a:visited {
border-bottom: 1px solid #DDD;
color: #333333;
cursor: default;
}
/*IMAGE style*/
img {
max-width: 100%;
height: auto;
}
.has-thumbnail {
position: relative;
padding-left: 200px;
}
.post-thumbnail {
position: absolute;
top: 0;
left: 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.