0% found this document useful (0 votes)
270 views1 page

Advanced Wordpress Cheat Sheet Sheet1

This document provides code snippets for advanced WordPress functions including: 1) Including content only on the home page, assigning unique images to categories, and styling different categories. 2) Adding previous/next post links, styling individual posts, and generating site page links. 3) Dynamically setting page titles and querying posts from a specific category. 4) Defining page templates, templates for categories, and CSS theme details. The snippets allow for customization of WordPress themes and content display.

Uploaded by

Aiza Musfira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
270 views1 page

Advanced Wordpress Cheat Sheet Sheet1

This document provides code snippets for advanced WordPress functions including: 1) Including content only on the home page, assigning unique images to categories, and styling different categories. 2) Adding previous/next post links, styling individual posts, and generating site page links. 3) Dynamically setting page titles and querying posts from a specific category. 4) Defining page templates, templates for categories, and CSS theme details. The snippets allow for customization of WordPress themes and content display.

Uploaded by

Aiza Musfira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Advanced

 WordPress  Cheat  Sheet


Content  Only  for  The  Home  Page Unique  Image  for  Different  Categories
<?php  if(is_home()  )  {  include  ('example.php');  }  ?> <?php  if  (is_category('7')  ):
This  snippet  will  include  the  file  specified,  only  if  the  user  is  on  the  home <img  src="<?php  bloginfo('template_url');?>/images/cat7.jpg'  alt="  />
page  of  the  site.  Place  this  code  in  the  index.php  file. <?php  elseif  (is_category('8')  ):
<img  src="<?php  bloginfo('template_url');?>/images/cat8.jpg'  alt="  />
<?php  endif;  ?>
Styiling  Different  Categories This  snippet  assings  an  image  (cat  7.jpg)  next  to  each  post  title  in  the  category  7  and  an
<?php  if  (is_category('15')  { image  (cat8.jpg)  next  to  each  post  title  in  category  8.  Place  this  code  in  the  category.php  
<link  rel="stylesheet"  href="<?php  bloginfo('template_url*);  ?>/cat-­‐15.css"
type="text/css"  media="screen"  />
<?php  }  else  {  ?> Styling  Individual  Posts
<link  rel="stylesheet"  href="<?php  bloginfo(stylesheet_url*);  ?>" <div  id="post-­‐<?php  the_ID();?>">
type="text/css"  media="screen"  /> This  snippet  will  assign  the  post  ID  to  the  DIV.  For  example,  if  the  ID  for  the  post  is  8,  that  
<?php  }  ?> line  will  echo  as  <div  id="post-­‐8"></div>.  Now  you  can  style  that  individual  post  in  the  CSS  
This  snippet  assigns  a  specific  stylesheet  (category-­‐15.css)  to  category  15   as  #post-­‐8.  Place  this  code  within  the  loop.
and  will  assign  the  rest  of  the  site  the  default  stylesheet  (style.css).  Place  this  code  in  the  
<head>  area.
Site  Page  Links
<ul>
Previous  &  Next  Posts  Links <li<?php  if(is_home())  {  ?>  class="current_page_item"<?php  }  ?>><a  href="
<?php  next_posts_link('Next  Entries  &raquo;')  ?> <?php  bloginfo('home');  ?>">home</a></li>
<?php  previous_posts_link('&raquo;  Older  Entries');  ?> <?php  wp_list_pages('sort_column=menu_order&depth=1&title_li=');  ?>
This  snippet  will  echo  "Next  Entries  >>"  with  a  link  to  the  next  set  of  posts.  The  second  snippet   </ul>
will  echo  "<<  Previous  Entries"  with  a  link  to  the  previous  set  of  posts.  Place  this  code  outside   This  snippet  will  first  echo  the  text  "home"  with  a  link  to  the  home  page.  Next,  it  will  echo  
the  loop. the  WordPress  pages  links  in  a  list,  in  order  defined  by  your  settings,  excluding  the  child  
pages,  and  excluding  a  title  header  for  the  list.  If  one  of  the  pages  in  the  list  is  active,  the  
link  for  that  page  will  be  assigned  the  class"corrent_page_item",  which  can  now  be  styled  
Dyniamic  Page  Titles
<?php
if  (is_home())  {  echo  bloginfo('name');  }  elseif  (is_404())  {  echo  'WPCandy  »  404';  }  elseif Query  Posts
(is_search())  {  echo  'WPCandy  »  Search  Results';  }  else  {  echo  'WPCandy  »  ';  wp_title('');  } <?php  query_posts('cat=2&showposts=5');?>
?> This  snippet  will  display  the  5  latest  posts  from  the  only  category  2.  Place  this  code  right
If  the  home  page  is  active,  the  title  will  display  the  name  of  the  site.  If  the  404  page  is  active,   before  the  loop.  
the  title  will  echo  'WPCandy  »  404'.  If  the  Search  Results  page  is  active,  the  title  will  echo
‘WPCandy  »  Search  Results’.  If  any  other  page  on  the  site  is  active,  the  title  will  display
Page  Template  Details
<?php
CSS  Theme  Details /*
/* Template  Name:  Gallery
Theme  Name:  StartBlogging */
Description:Description  goes  here ?>
Theme  URL:  http://startbloggingonline.com/ This  snippet  defines  a  page  template.  You  will  also  need  to  have  a  corresponding  file  to  use  
Version:  2.0 as  the  new  page  template.For  example,  in  this  case,  you  would  create  a  gallery.php  file.  
Author:  Mike  W.
Author  URL:  http//startbloggingonline.com/
Template:  Degine  a  parent  template  (optional) Unique  Template  for  Categories
*/ <?php
This  snippet  defines  a  theme.  WordPress  will  read  this  and  assign  it  to  the  theme.  Use  the   $post  =  $wp_query-­‐  >post;
'Template:'  to  define  a  parent  template  for  the  theme.  Place  this  code  at  the  top  of  the  
syle.css  file. if  (  in_category('3')  )  {
include(TEMPLATEPATH  .  '/cat3.php’);

The  Loop  }  elseif  (  in_category('4')  )  {


<?php  if  (have_posts())  :  ?> include(TEMPLATEPATH  .  '/cat4.php');
<?php  while(have_posts())  :  the_post();?>
//  Post  content  here  (Custom  HTML  &  PHP  code)  }  else  {
<?php  endwhile;  ?>  include(TEMPLATEPATH  .  '/cat.php');
<?php  else  :  ?>  }  ?  >
<?php  endif;  ?> This  snippet  will  assign  a  uniqe  template  to  certain  categories.  In  this  case,  'cat3.php'  will  
This  snippet  is  the  basic  form  of  the  loop.  WordPress  will  read  the  code  between  the   be  assigned  to  'Category3',  'cat4.php'  will  be  assigned  to  Category  4',  and  the  rest  of  the  
beginning  of  the  loop  and  the  end  of  the  loop,  and  display  it  accordingly  on  each  post  or  page.   categories  will  be  assigned  'cat.php'.  Place  this  code  at  the  top  of  category.php.
Any  HTML  or  PHP  placed  inside  the  loop  will  be  used  for  each  post.  Place  this  code  in  any  

Tags  Cloud
<?php  wp_tag_cloud('smallest=1&largest=9&');  ?>
This  snippet  will  create  a  tag  cloud,  in  alphabetical  order,  with  the  smallest  text  at  1  pt  and
the  largest  text  at  9  pts.

Created  by  StartBloggingOnline.com

You might also like