Está en la página 1de 6

====================

Display current year


====================
Usually post in Footer.php
<?php the_time('Y') ?>
EX:
<p>Copyright &copy; <?php the_time('Y') ?>, Jona</p>
======================
Display Featured image
======================
Post in Function.php:
//Enable support for Featured Image
add_theme_support( 'post-thumbnails' );
OPTIONAL:
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 100, 50, true ); // sets the image size
Display Feature Image in your post:
<div class="col-sm-5 col-md-5 purchase-img">
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assi
gned to it.
the_post_thumbnail();
}
?>
</div>

===========================================
Display thumbnail according to desired size
===========================================
Post in Function.php:
add_image_size( 'sponsor-thumb', 9999, 67 ); //9999 auto
OR
add_image_size( 'team-thumb', 100, 9999 ); //9999 auto
OR
add_image_size( 'events-thumb', 205, 185 );
Display the thumbnail on your samplepage.php:
<a href="<?php the_permalink()?>"><?php the_post_thumbnail('events-thumb');?> </
a>

========================================
Display images from themes images folder
========================================
<img src="<?php echo get_template_directory_uri(); ?>/images/twitter.png" alt=""
>
<?php echo get_template_directory_uri(); ?>

ex:
<?php echo get_template_directory_uri(); ?>/images/twitter.png" alt="">

========================
Register another sidebar
========================
Post in Function.php
function --themename--_widgets_init() {
register_sidebar( array(
'name'
=> __( 'Home Widget', 'steelpoint' ),
'id'
=> 'home-widget',
'before_widget' => '<aside id="%1$s" class="col-sm-4 col-md-4 widget %2$s">'
,
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', '--themename--_widgets_init' );

===============================
Add tags after the content post
===============================
add_filter ('the_content', 'insertContent');
function insertContent($content) {
$content .= 'Stuff to add after content';
return $content;
}

===============================
Add Tags and Categories to Page
===============================
//Pages Tags &amp; Category Meta boxes
function add_pages_meta_boxes() {
add_meta_box( 'tagsdiv-post_tag', __('Page Tags'), 'post_tags_meta_box', 'page
', 'side', 'low');
add_meta_box( 'categorydiv', __('Categories'), 'post_categories_meta_box', 'pa
ge', 'normal', 'core');
}
add_action('add_meta_boxes', 'add_pages_meta_boxes');
add_action('init','attach_category_to_page');
function attach_category_to_page() {
register_taxonomy_for_object_type('category','page');
}

=======================================
Display contents from specific category
=======================================
cat=7&posts_per_page=10 = 7(category ID), 10(number of posts to display)

<?php
$catquery = new WP_Query( 'cat=7&posts_per_page=10' );
while($catquery->have_posts()) : $catquery->the_post();
?>
<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
<?php echo get_the_post_thumbnail(); ?>
<?php the_content(); ?>
<?php the_date(); ?>
<?php endwhile; ?>

===============
Echo page title
===============
<?php echo get_the_title(); ?>

===========================
Hide title on specific page
===========================
.page-id-31 h1.h3.entry-title{
display: none !important;
}

=============================================
Echo only the post(paragraphs of the content)
=============================================
<?php
$content = get_the_content('Read more');
print $content;
?>

=================================
Echo only the content of the post
=================================
<?php the_content(); ?>

=======================
Echo Gallery in Content
=======================
<?php /* The loop */
while ( have_posts() ) : the_post();
if ( get_post_gallery() ) :
echo get_post_gallery();
endif;
endwhile;
?>
http://codex.wordpress.org/Function_Reference/get_post_gallery

=========================
Echo post date and author
=========================
Note: author link direct you to whatever link you inserted in admin profile.
echo author link that directs to authors posts : <?php the_author_posts_li
nk(); ?>
<p class="entry-meta"><?php billiant_designs_posted_on(); ?> by <?php echo get_t
he_author_link(); ?></p>

=========================================
Display recent posts [with feature image]
=========================================
<?php query_posts('cat=#&posts_per_page=5'); ?>
<?php while (have_posts()) : the_post(); ?>
<li>
<h4><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></h4>
<?php the_date(); ?>
<?php the_excerpt(); ?>
<a href="<?php echo get_permalink(); ?>">
<?php the_post_thumbnail('large_wide'); ?>
</a>
</li>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
Another ex:
----------<main id="main" class="site-main col-sm-9 col-md-9 blog-entries" role="main">
<?php query_posts('cat=#&posts_per_page=5'); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="row">
<div class="col-sm-4 col-md-4">
<a href="<?php echo get_permalink(); ?>">
<?php the_post_thumbnail(); ?>
</a>
</div>
<div class="col-sm-8 col-md-8">
<h4><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></
h4>
<p class="entry-meta"><?php billiant_designs_posted_on(); ?> by <?php ec
ho get_the_author_link(); ?></p>
<?php the_content_limit(150); ?><!--this needs a plugin-->
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</main><!-- #main -->

=============================================
Display recent posts titles[no feature image]
=============================================
<h2>Recent Posts</h2>
<ul>
<?php
$recent_posts = wp_get_recent_posts();

foreach( $recent_posts as $recent ){


echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_a
ttr($recent["post_title"]).'" >' . $recent["post_title"].'</a>
</li> ';
}
?>
</ul>

========================================================
Echo posts image, title and content of specific category
========================================================
<!--test-->
<?php
query_posts( array('posts_per_page'=>5, 'category_name'=>'Cooling Towers') )
;
while ( have_posts() ) : the_post();
?>
<h2><a href="<?php the_permalink(' ') ?>" title="<?php the_title(); ?>"><?ph
p the_title(); ?></a></h2>
<?php if ( has_post_thumbnail() ): // check for the featured image ?>
<a href="<?php the_permalink(' ') ?>" title="<?php the_title(); ?>" class="o
pacity"><?php the_post_thumbnail(); ?></a> <!--echo the featured image-->
<?php
endif;
the_excerpt(); // echo the excerpt
endwhile;
wp_reset_query(); // resets main query
?>
<!--end test-->

=======================================
Display next/prev in post titles format
=======================================
<?php
previous_post_link('<span class="left">&laquo; %link</span>');
next_post_link('<span class="right">%link &raquo;</span>');
?>
<div class="clearfix"></div>
Output:
Blog Post two Blog Post Four

===========================================================
Display next/prev in Newer Entries/Older Entries format
===========================================================
<?php next_posts_link('Older Entries ', 0); ?>
<?php previous_posts_link(' Newer Entries', '0') ?>
Output:
Newer Entries/Older Entries
http://speckyboy.com/2012/10/01/next-and-previous-links-on-wordpress-posts/

También podría gustarte