wordpress alternate colors to page links

Home » Blog » wordpress alternate colors to page links

Using following code you can apply two colors alternatively to the page links. just edit the colors to apply different styles.

<ul class="page_navigation">
<?php
$pages = get_pages(array('sort_column'=>'menu_order'));
$totalpages=count($pages);
$count=0;
foreach ($pages as $pagg) {
$count++;
if($count%2!=0)
{
echo '<li class="odd">';
}
else
{
echo '<li class="even">';
}
echo '<a href="'.get_permalink($pagg->ID).'">';
echo $pagg->post_title;
echo '</a></li>';
}
?>
</ul>
<style type="text/css">
.page_navigation li.odd a
{
	color:red;
}
.page_navigation li.even a
{
	color:blue;
}
</style>

And if you want to display child pages of a specific page then just replace line

$pages = get_pages(array('sort_column'=>'menu_order','child_of'=>8));

change 8 with parent page id and display child pages of that parent.

and if you want to display child pages of current page then just add $post->ID instead of the page number.
like

$pages = get_pages(array('sort_column'=>'menu_order','child_of'=>$post->ID));

Tags: , ,

4 Comments on "wordpress alternate colors to page links"

  1. Sandy says:

    How do I move the black navigation buttons to the bottom right from bottom center?

    thanks

    Reply →
    • snilesh says:

      in content_slide.php file search for css code

      #wpcontent_slider_container .cs-buttons
      {
      font-size: 0px; padding: 10px 0px 10px 0px;
      margin:0px auto; float:left;clear:left;
      }
      

      change this to

      #wpcontent_slider_container .cs-buttons
      {
      font-size: 0px; padding: 10px 0px 10px 0px;
      margin:0px; float:right;clear:left;
      }
      
      Reply →
  2. chandra says:

    thanks,
    but i need wordpress alternate colors to the recent post links.

    please…..

    Reply →

Got something to say? Go for it!

How to remove the http://t.co/XhUQ8T6p link from Login / Register Page: On self hosted wordpress blogs wordpress ... http://t.co/LWDOuEfq - 1 week ago