WordPressGuide

ALL Functions By Category

Source Code: https://codex.wordpress.org/Function_Reference

 Comment Side

Custom Functions

Source: https://www.youtube.com/watch?v=gCq2p1ImbaE

Get the Title

<?php get_the_title(); ?>

Creating Menus –

in Function.php
function register_my_menus() {
register_nav_menus(
array(
‘new-menu’ => __( ‘New Menu’ ),
‘another-menu’ => __( ‘Another Menu’ ),
‘an-extra-menu’ => __( ‘An Extra Menu’ )
)
);
}
add_action( ‘init’, ‘register_my_menus’ );
in header.php

<?php wp_nav_menu( array( ‘theme_location’ => ‘new-menu’ ) ); ?>

Call Post Queries –

// Define our WP Query Parameters
<?php $the_query = new WP_Query( ‘posts_per_page=5’ ); ?>

// Start our WP Query
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>

// Display the Post Title with Hyperlink
<li><a href=”<?php the_permalink() ?>”><?php the_title(); ?></a></li>

// Display the Post Excerpt
<li><?php the_excerpt(__(‘(more…)’)); ?></li>

// Repeat the process and reset once it hits the limit
<?php
endwhile;
wp_reset_postdata();
?>

Get All Category List Title

<?php wp_list_categories($args); ?><

Get the Author –

<?php the_author(); ?>

Get the date –

<?php get_the_date();?>
or
<?php echo the_date(); ?>

Get Comment Count –

<?php comments_number()?>

Post Query from Single –

<!– Post Query –>

<?php while ( have_posts() ) : the_post(); ?>
<?php endwhile;?>

Get More Post –

<?php
$args = array( ‘numberposts’ => 10, ‘order’=> ‘ASC’, ‘orderby’ => ‘title’ );
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post); ?>
<div>
<?php the_date(); ?>
<br />
<?php the_title(); ?>
<?php the_excerpt(); ?>
</div>
<?php endforeach; ?>

Sidebar Widget Integration-

functions.php

function yavin_widgets_init() {
register_sidebar( array(
‘name’ => __( ‘Widget Area’, ‘twentyfifteen’ ),
‘id’ => ‘sidebar-1’,
‘description’ => __( ‘Add widgets here to appear in your sidebar.’, ‘twentyfifteen’ ),
‘before_widget’ => ‘<aside id=”%1$s” class=”widget %2$s”>’,
‘after_widget’ => ‘</aside>’,
‘before_title’ => ‘<h2 class=”widget-title”>’,
‘after_title’ => ‘</h2>’,
) );
}
add_action( ‘widgets_init’, ‘yavin_widgets_init’ );
sidebar.php

<?php dynamic_sidebar( ‘sidebar-1’ ); ?>

Get Post Featured Image –

functions.php

add_theme_support( ‘post-thumbnails’ );
sidebar.php

<?php the_post_thumbnail();?>

Guide to set permalink –

<?php the_permalink();?>

you need to set Template part for displaying single posts. (singlepage.php)

Guide to set category Page –

Create a Content.php
<div class=”col-md-6 abt-left”>
<a href=”<?php the_permalink(); ?>”><?php the_post_thumbnail(‘thumbnail’);?></a>
<h6>Find The Most</h6>
<h3><a href=”<?php the_permalink(); ?>”><?php the_title();?></a></h3>
<p><?php the_excerpt(__(‘(more…)’)); ?></p>

Title –

<title><?php wp_title( ‘|’, true, ‘right’ ); ?></title>

 

Load CSS in functions.php

function cuyi_styles()
{
// Load all of the CSS styles that need to appear on all pages
wp_enqueue_style( ‘main’, get_template_directory_uri() . ‘/style.css’, array(), null );
wp_enqueue_style( ‘bootstrap’, get_template_directory_uri() . ‘/css/bootstrap.min.css’, array(), null );
wp_enqueue_style( ‘custont-awesome’, get_template_directory_uri() . ‘/css/font-awesome.min.css’, array(), null );
wp_enqueue_style( ‘owl-carousel’, get_template_directory_uri() . ‘/css/owl.carousel.css’, array(), null );
wp_enqueue_style( ‘responsive’, get_template_directory_uri() . ‘/css/responsive.css’, array(), null );

// Conditionally load the FlexSlider CSS on the homepage

}
add_action(‘wp_enqueue_scripts’, ‘cuyi_styles’);

HTML Language

<?php language_attributes(); ?> insted of  <meta charset=”utf-8″>

Meta Charset

<meta charset=”<?php bloginfo( ‘charset’ ); ?>”>  Instead of      <meta charset=”utf-8″>

Get Post By Category

<?php   // The Query query_posts

( array ( ‘category_name’ => ‘WordPress Themes’, ‘posts_per_page’ => -1 ) );

// The Loop while

( have_posts() ) : the_post(); ?> <li> <a href=”<?php the_permalink() ?>” title=”<?php the_title(); ?>”><?php the_title(); ?></a> </li>   <?php endwhile;

// Reset Query

wp_reset_query();   ?>

Get Category Title per posts

<?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?>


Get Post by Category ID

<div class=”col-md-8″>
<h1 style=”color:#000;”> Recent Post </h1>

<?php query_posts(‘cat=6′); while (have_posts()) : the_post(); ?>
<h2 style=”list-style: none;”><li><a href='<?php the_permalink() ?>’><?php the_title(); ?></a></li></h2>
<?php the_post_thumbnail(‘medium’); ?>
<p><?php the_excerpt(); ?></p>
<button class=”btn btn-primary”><a style=”color:white;” href=”<?php the_permalink() ?>”> Read More </a> </button>

<?php endwhile; ?>

<?php wp_reset_query(); ?>

</div>

<div class=”col-md-4″><h1 style=”color:#000;”> Blogs </h1>
<?php query_posts(‘cat=6′); while (have_posts()) : the_post(); ?>
<h4 style=”list-style: none;”><li><a href='<?php the_permalink() ?>’><?php the_title(); ?></a></li></h4>
<?php endwhile; ?>
</div>
</div>
</div>