Michele
Michele

Reputation: 121

displaying count of wordpress posts

I'm trying to display the number of wordpress posts in a ticker-clock-like fashion, but the numbers are not displaying. Is my code right? In functions.php, I wrote:

<?php
$totalposts = wp_count_posts();
$postsepnumbers = array_pad(str_split($totalposts), -3, "");

because I want three digits to display. I left off the closing ?> to eliminate the whitespace problem.

then I want to display them as a ticker like here: this site so in my front-page.php I added

<div class=counterwrapper"><div class="countbox"><center>We currently have <span><?php echo $postsepnumbers[0]; ?></span><span><?php echo $postsepnumbers[1]; ?></span><span><?php echo $postsepnumbers[2]; ?></span> things to do listed here.  Add your ideas!!</center></div></div>

And the css is

.countbox {
color: #CCCCCC;
background: linear-gradient(to bottom, #3d3d3d 0%,#4c4c4c 25%,#1c1c1c 52%,#161616 52%,#2b2b2b 76%,#131313 100%);
border-radius: 4px;
font-weight: bold;
font-family: "proxima-nova", sans-serif;
display: inline-block;
border: 1px solid #181818;
height: 60px;
}
.countbox span {
display: inline-block;
border-right: 2px solid #111;
padding: 4px 2px;
font-size: 1.8em;
width: 30px;
text-align: center;
line-height: 1em;
text-shadow: 0 -1px 1px #000;
color: #fff;
}

I didn't add any css for "counterwrapper" because I wanted to get it to work first. But if you see here: site no numbers display.

I don't understand why I can't get it to display the numbers.

Upvotes: 1

Views: 81

Answers (1)

asanchez
asanchez

Reputation: 474

The function wp_count_post() return an objet, not an array. That's the only reason your code is not working. You can find here examples of how to use it: http://codex.wordpress.org/Function_Reference/wp_count_posts

May be you could try that:

<?php
$totalposts = wp_count_posts();
$postsepnumbers = array_pad(str_split($totalposts->publish), -3, "");

That should show the number of published post.

Upvotes: 1

Related Questions