Entries Tagged 'Wordpress Functions' ↓

Display Wordpress Post Number on Single Page with post ID

You can see it work throughout this wordpress blog, to the right you see DCE Article 94. Notice you can select the number as text. The number is pulled from the post on every single page by placing this line of code in your wordpress single.php template page.

<?php the_ID(); ?>

Note: When using this line of code be sure it is between these two lines of code in your single.php page

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

<?php endwhile; else: ?>

I place the code in its own div with a background image to create the illusion of unity. I use margins to move the number to the right spot of the image. My CSS and Code looks like this.

<style>
#page_number_id_spawn { float:left; text-align:right; margin-top:240px; width:135px; color:#900; font-size:30px; font-family:Georgia, 'Times New Roman', Times, serif;}</style>

<div id="page_number_id_spawn"><?php the_ID(); ?></div>

List 10 Most Recent Posts in Wordpress Sidebar

No plugin needed, you can list however many recent posts by title using the wp_get_archives function. Insert this code into your sidebar.php

<ul> <?php wp_get_archives(’type=postbypost&limit=10'); ?> </ul>

The limit can be adjust to any number of posts.