PHP get the first post separately from array returned by wpdb->get_results()

once you have set of result in particular order you can achieve it simply as below : – $pageposts=$wpdb->get_results(” SELECT * FROM $wpdb->posts WHERE post_type=”post” AND post_status=”publish” ORDER BY post_date DESC LIMIT 6 “, OBJECT); First time $i=1; foreach($pageposts as $pageposts_first){ //here goes your first post if($i==1) break; } For rest of posts $i=0; foreach($pageposts … Read more

How to make “more” or “continue reading” links on excerpts nofollow?

In your theme’s functions.php: /* Returns a “Continue Reading” link for excerpts, with ‘nofollow’ set */ function your_theme_continue_reading_link() { return ‘ <a href=”‘. get_permalink() . ‘” rel=”nofollow”>’ . ‘<span class=”meta-nav”>&rarr;</span> Continue reading</a>’; } /* Replaces “[…]” (appended to automatically generated excerpts) */ function your_theme_auto_excerpt_more( $more ) { return ‘ &hellip;’ . your_theme_continue_reading_link(); } add_filter( ‘excerpt_more’, … Read more

How to create a linked tag list in my sidebar

This will output a list of all tags, sorted by the most used tag first. Each tag has the number of times it has been used following the tag in parentheses. The parentheses and number of times used is in a <span>. To remove the parentheses, change <span>(‘ . $tag->count . ‘)</span> to <span>’ . … Read more

Remove posts after a given amount of time

You can use wp_delete_post() and get_the_date(). global $wpdb; if ( !is_user_logged_in()) echo ‘You must be logged in.’; // check if title $my_post_name already exists in wpdb else if ( is_user_logged_in()&& $wpdb->get_row(“SELECT post_title FROM wp_posts WHERE post_title=”” . $my_post_name . “””, ‘ARRAY_A’)) { // then check age of the post? assign age to a variable? $time … Read more

How does the ternary operator work in the wordpress loop post?

The double colon in this case is part of the alternative syntax for control structures. That’s not the ternary operator. You could also write instead: if ( have_posts() ) { while( have_posts() ) { the_post(); the_content(); } } I prefer the second style, most code editors enable automatic folding with it, so I can close … Read more

How to create a custom category of wordpress admin

You might consider the idea of creating a custom post type called ticker. On the custom post type, add a custom field (input field) and store it as the value. Then one option would be to use code of this nature in your homepage template: <?php $args = array(     ‘numberposts’     => 5, // how many posts will be in the … Read more