Wp_query from ajax editor

Hi I have a query that I would like to pull a random post and then ticker tape the name and url across the screen. I have everything working but I cannot get a spacing added to the exploded array from wp_query


Thank you in advanced this is my first foray into php

if($random_post -> have_posts() ) {
    while($random_post -> have_posts() ) {
        $random_post -> the_post();
        $listed='<a href="'.get_the_permalink().'">'.get_the_title().'</a>';
        $pieces = explode(" " ,"$listed");
        echo $pieces[ 0 ],$pieces[ 1 ],$pieces[ 2 ],$pieces[ 3 ];

This snippet makes it look like you have yourself a little crossed up. I assume you want a different link for each item? If that’s what you want, you can write it like so:

if ($random_post->have_posts() ) {
    while ($random_post->have_posts() ) {
        echo '<div class="ticker-item"><a href="'.get_the_permalink().'">'.get_the_title().'</a></div>';

The while loop will run once for each post in your list. You want to print out a link for each item in the list, so that’s all you do.

oh I see surrounding it in the div class will separate it
that’s interesting thanks

No problem. As an aside: Noone wants to see a ticker tape on a website :slight_smile:

There was a tag explicitly for doing this - the marquee tag - but it’s being removed from the standard. Noone wants to chase content around the screen to read or click on it.

Sponsor our Newsletter | Privacy Policy | Terms of Service