Sei sulla pagina 1di 13

<!

--============================================================================
========================
=Display Post with Featured Image
================================================================================
==================== -->
- Date , Time
- Title
- Featured Image
- Content
- Display message if no post is found
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<p class="date">Date: <span><?php the_date() ?> , <?php the_time() ?></s
pan></p>
<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbn
ail assigned to it.
the_post_thumbnail();
}
?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php else : ?>
<h2>No Item Found</h2>
<p>Sorry, There are no available content post at this time.</p>
<?php endif; ?>

<!--============================================================================
========================
=Display Latest posts
================================================================================
==================== -->
<div class="latest-posts alignleft">
<?php $the_query = new WP_Query( 'showposts=3' ); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<div class="col-md-4 clearfix">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
<h3><a href="<?php the_permalink() ?>"><?php the_title()
; ?></a></h3>
<?php echo substr(strip_tags($post->post_content), 0, 11
0);?>
</div>
<?php endwhile;?>

</div><!--end latest-post-->

<!--============================================================================
========================
=Display single post of specific category (Featured)
================================================================================
==================== -->
<div class="featured-post">
<?php
query_posts(array('category_name' => 'featured', 'posts_per_page
' => '1'));
if(have_posts()): the_post();
$do_not_duplicate = $post->ID; // set up the post so you can ski
p it later
$thumbnail = get_the_post_thumbnail($post->ID);?>
<div id="post-<?php the_ID(); ?> <?php post_class(); ?>">
<h2><a href="<?php the_permalink() ?>"><?php the_title()
; ?></a></h2>
<?php echo $thumbnail; // the Featured image set with the po
st ?>
<?php the_excerpt(); ?>
</div>
<?php endif; wp_reset_query(); ?>
</div>

<!--============================================================================
========================
=Display posts of specific category (Services)
================================================================================
==================== -->
<div class="row">
<?php
$catquery = new WP_Query( 'category_name=services&posts_per_page=3' );
while($catquery->have_posts()) : $catquery->the_post();
?>
<div class="col-sm-4 col-md-4 services clearfix">
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
</div><!--end row-->

<!--============================================================================
========================
=Display List of Posts in Page with navigation
================================================================================
==================== -->
<?php
$temp = $wp_query; $wp_query= null;
$wp_query = new WP_Query(); $wp_query->query('showposts=3' . '&paged='.$
paged);
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<h2><a href="<?php the_permalink(); ?>" title="Read more"><?php the_titl
e(); ?></a></h2>
<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php if ($paged > 1) { ?>
<nav id="nav-posts">
<div class="prev"><?php next_posts_link('&laquo; Previous Posts'
); ?></div>
<div class="next"><?php previous_posts_link('Newer Posts &raquo;
'); ?></div>
</nav>
<?php } else { ?>
<nav id="nav-posts">
<div class="prev"><?php next_posts_link('&laquo; Previous Posts'
); ?></div>
</nav>
<?php } ?>
<?php wp_reset_postdata(); ?>

<!--============================================================================
========================
=Display List of Subpages in Parent page
================================================================================
==================== -->
<?php
$args = array(
'post_type'
'posts_per_page'
'post_parent'
'order'
'orderby'
);

=>
=>
=>
=>
=>

'page',
-1,
//-1 shows all sub-pages
$post->ID,
'ASC',
'menu_order'

$parent = new WP_Query( $args );


if ( $parent->have_posts() ) : ?>

<?php while ( $parent->have_posts() ) : $parent->the_post(); ?>


<?php
global $more;
$more = 0;
?>
<?php echo get_the_post_thumbnail( $page->ID ); ?>
<h4 class="entry-title"><a href="/<?php echo get_page_link( $pag
e->ID ); ?>"><?php the_title(); ?></a></h4>
<div class="front-page entry-content" id="<?php echo $page->post_name; ?
>">
<?php the_content('<p style="text-align:right">> read more</p>'); ?></p>
</div>
<?php endwhile; ?>
<?php endif; wp_reset_query(); ?>

<!--============================================================================
========================
=Display List of Subpages in Parent page with Pagination
================================================================================
==================== -->
<?php
$postIDs = array();
$pageChildren = get_pages('child_of=' . $post->ID . '&exclude=' . $exclude_page
);
if ( $pageChildren ) {
foreach ( $pageChildren as $pageChild ) {
$postIDs[] = $pageChild->ID;
}
$paged = (intval(get_query_var('paged'))) ? intval(get_query_var('paged')) : 1
;
$args = array(
'post_type' => 'page',
'paged' => $paged,
'post__in' => $postIDs,
'posts_per_page' => 2
);
query_posts($args);
if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<div class="entry">
<?php the_excerpt('<p class="serif">Read the rest of this page </p>'); ?>
<?php wp_link_pages(array('before' => '<p>Pages: ', 'after' => '</p>', 'ne
xt_or_number' => 'number')); ?>
</div>
</div>

<?php endwhile; ?>


<div class="navigation">
<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></di
v>
<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?
></div>
</div>
<?php endif; ?>
<?php } ?>

<!--============================================================================
========================
=Display Numbered Pagination
================================================================================
==================== -->
function wpbeginner_numeric_posts_nav() {
if( is_singular() )
return;
global $wp_query;
/** Stop execution if there's only 1 page */
if( $wp_query->max_num_pages <= 1 )
return;
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) :
1;
$max

= intval( $wp_query->max_num_pages );

/**
Add current page to the array */
if ( $paged >= 1 )
$links[] = $paged;
/**
Add the pages around the current page to the array */
if ( $paged >= 3 ) {
$links[] = $paged - 1;
$links[] = $paged - 2;
}
if ( ( $paged + 2 ) <= $max ) {
$links[] = $paged + 2;
$links[] = $paged + 1;
}
echo '<div class="navigation"><ul>' . "\n";
/**
Previous Post Link */
if ( get_previous_posts_link() )
printf( '<li>%s</li>' . "\n", get_previous_posts_link() );
/**
Link to first page, plus ellipses if necessary */
if ( ! in_array( 1, $links ) ) {
$class = 1 == $paged ? ' class="active"' : '';

printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url


( get_pagenum_link( 1 ) ), '1' );
if ( ! in_array( 2, $links ) )
echo '<li> </li>';
}
/**

Link to current page, plus 2 pages in either direction if necess

ary */
sort( $links );
foreach ( (array) $links as $link ) {
$class = $paged == $link ? ' class="active"' : '';
printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url
( get_pagenum_link( $link ) ), $link );
}
/**
Link to last page, plus ellipses if necessary */
if ( ! in_array( $max, $links ) ) {
if ( ! in_array( $max - 1, $links ) )
echo '<li> </li>' . "\n";
$class = $paged == $max ? ' class="active"' : '';
printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url
( get_pagenum_link( $max ) ), $max );
}
/**
Next Post Link */
if ( get_next_posts_link() )
printf( '<li>%s</li>' . "\n", get_next_posts_link() );
echo '</ul></div>' . "\n";
}

//post in area you want the numbered pagination to appear(blog-page.php)


<?php wpbeginner_numeric_posts_nav(); ?>

<!--============================================================================
========================
=Featured Image link to Large Image
================================================================================
==================== -->
<?php
if ( has_post_thumbnail()) {
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(),
'large');
echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribu
te('echo=0') . '" >';
the_post_thumbnail('full');
echo '</a>';
}

?>

<!--============================================================================
========================
=Add # on navigation links
================================================================================
==================== -->
function.php
-----------class description_walker extends Walker_Nav_Menu{
function start_el(&$output, $item, $depth, $args){
global $wp_query;
$indent = ( $depth ) ? str_repeat( " ", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes
;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_
filter( $classes ), $item ) );
$class_names = ' class="'. esc_attr( $class_names ) . '"';
$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value .
$class_names .'>';
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr(
$item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target )
? ' target="' . esc_attr(
$item->target
) .'"' : '';
$attributes .= ! empty( $item->xfn )
? ' rel="'
. esc_attr(
$item->xfn
) .'"' : '';
if($item->object == 'page')
{
$varpost = get_post($item->object_id);
if(is_home()){
$attributes .= ' href="#' . $varpost->post_name . '"';
}else{
$attributes .= ' href="'.home_url().'/#' . $varpost->post_name
. '"';
}
}
else
$attributes .= ! empty( $item->url )
? ' href="' . esc_
attr( $item->url
) .'"' : '';
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= $args->link_before . apply_filters( 'the_title', $it
em->title, $item->ID );
$item_output .= $args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output,
$item, $depth, $args );
}
}

header.php
----------

<?php
wp_nav_menu( array(
'theme_location' => 'primary',
'echo' => true,
'walker'=> new Description_Walker,
'depth' => 4) );
?>

<!--============================================================================
========================
=Display Gallery and Images on separate divs
================================================================================
==================== -->
functions.php
------------function strip_shortcode_gallery( $content ) {
preg_match_all( '/'. get_shortcode_regex() .'/s', $content, $matches, PREG_S
ET_ORDER );
if ( ! empty( $matches ) ) {
foreach ( $matches as $shortcode ) {
if ( 'gallery' === $shortcode[2] ) {
$pos = strpos( $content, $shortcode[0] );
if ($pos !== false)
return substr_replace( $content, '', $pos, strlen($shortcode
[0]) );
}
}
}
return $content;
}

single.php
---------<div class="col-sm-6 col-md-6">
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
<?php
$gallery = get_post_gallery();
$content = strip_shortcode_gallery( get_the_content() );
$content = str_replace( ']]>', ']]&gt;', apply_filters( 'the_content', $content
) );
?>
<?php echo $gallery; ?>
</div>
<div class="col-sm-6 col-md-6">
<div class="aligncenter">
<h2><?php the_title(); ?></h2>
<p><?php echo $content; ?></p>

</div>
</div>
<?php endwhile; ?>
<?php endif; ?>

<!--============================================================================
========================
=Display Gallery and Images on separate divs - Another option
================================================================================
==================== -->
single.php
---------<div class="col-sm-6 col-md-6">
/* The loop */
while ( have_posts() ) : the_post();
if ( get_post_gallery() ) :
$gallery = get_post_gallery( get_the_ID(), false );
/* Loop through all the image and output them one by one */
foreach( $gallery['src'] AS $src )
{
?>
<img src="<?php echo $src; ?>" class="my-custom-class" alt="Gall
ery image" />
<?php
}
endif;
endwhile;
?>
</div>
<div class="col-sm-6 col-md-6">
<div class="aligncenter">
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
</div>
</div>

<!--============================================================================
========================
=Display Gallery
================================================================================
==================== -->
template.php
-----------<?php /* The loop */
while ( have_posts() ) : the_post();
if ( get_post_gallery() ) :
echo get_post_gallery();
endif;
endwhile;
?>

<!--============================================================================
========================
=Display Gallery in img with custom class
================================================================================
==================== -->
<?php
/* The loop */
while ( have_posts() ) : the_post();
if ( get_post_gallery() ) :
$gallery = get_post_gallery( get_the_ID(), false );
/* Loop through all the image and output them one by one */
foreach( $gallery['src'] AS $src )
{
?>
<img src="<?php echo $src; ?>" class="my-custom-class" alt="
Gallery image" />
<?php
}
endif;
endwhile;
?>

<!--============================================================================
========================
=Display Gallery in li (garabs all attachement of a specific category)
================================================================================
==================== -->
<ul>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo '<li>';
echo wp_get_attachment_image( $attachment->ID, 'full' );
echo '<p>';
echo apply_filters( 'the_title', $attachment->post_title );
echo '</p></li>';
}
}
endwhile; endif; ?>
</ul>

<!--============================================================================
========================
=Display Gallery in li
================================================================================
==================== -->
function.php
-----------function custom_gallery( $output, $attr ){
global $post, $wp_locale;
static $instance = 0;
$instance++;
// We're trusting author input, so let's at least make sure it looks like a vali
d orderby statement
if ( isset( $attr['orderby'] ) ) {
$attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
if ( !$attr['orderby'] )
unset( $attr['orderby'] );
}
extract(shortcode_atts(array(
'order'
=> 'ASC',
'orderby'
=> 'menu_order ID',
'id'
=> $post->ID,
'itemtag'
=> 'li',
'icontag'
=> '',
'captiontag' => '',
'columns'
=> 3,
'size'
=> 'full',
'include'
=> '',
'exclude'
=> ''
), $attr));
$id = intval($id);
if ( 'RAND' == $order )
$orderby = 'none';
if ( !empty($include) ) {
$include = preg_replace( '/[^0-9,]+/', '', $include );
$_attachments = get_posts( array('include' => $include, 'post_status' => 'in
herit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $or
der, 'orderby' => $orderby) );
$attachments = array();
foreach ( $_attachments as $key => $val ) {
$attachments[$val->ID] = $_attachments[$key];
}
} elseif ( !empty($exclude) ) {
$exclude = preg_replace( '/[^0-9,]+/', '', $exclude );
$attachments = get_children( array('post_parent' => $id, 'exclude' => $exclu
de, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' =>
'image', 'order' => $order, 'orderby' => $orderby) );
} else {
$attachments = get_children( array('post_parent' => $id, 'post_status' => 'i
nherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $o
rder, 'orderby' => $orderby) );
}

if ( empty($attachments) )
return '';
if ( is_feed() ) {
$output = "\n";
foreach ( $attachments as $att_id => $attachment )
$output .= wp_get_attachment_link($att_id, $size, true) . "\n";
return $output;
}
$itemtag = tag_escape($itemtag);
$captiontag = tag_escape($captiontag);
$columns = intval($columns);
$itemwidth = $columns > 0 ? floor(100/$columns) : 100;
$float = is_rtl() ? 'right' : 'left';
$selector = "gallery-{$instance}";
$gallery_div = '';
$size_class = sanitize_html_class( $size );
$gallery_div = "<ul id=\"$selector\" class=\"gallery galleryid-{$id} gallery-col
umns-{$columns} gallery-size-{$size_class}\">";
$output = apply_filters( 'gallery_style', $gallery_div );
$i = 0;
foreach ( $attachments as $id => $attachment ) {
$image = wp_get_attachment_image( $id, $size );
$output .= "<{$itemtag} class=\"gallery-item\">";
$output .= $image;
if ( $captiontag && trim($attachment->post_excerpt) ) {
$output .= "
<{$captiontag} class=\"wp-caption-text gallery-caption\">
" . wptexturize($attachment->post_excerpt) . "
</{$captiontag}>";
}
$output .= "</{$itemtag}>";
}
$output .= "
</ul>\n";
return $output;
}
add_filter('post_gallery', 'custom_gallery', 11, 2);

Potrebbero piacerti anche