lukdol
Forum Replies Created
-
Forum: Themes and Templates
In reply to: [OnePress] Add HTML-elements to the headerThanks for pointing in the right direction. I also want to put some other stuff in the header, not just changing the form. I followed the same procedure: Copied the onepress_site_header function to my functions.php and added html there. It works! So easy…
Thank you for the fast answer!Yes, that’s it now! This is the correct answer!
Thank you @alichani – quick and simple.
Good evening @alichani and community!
After intensive testing, there is one more problem.
The solution works pages and single pages, but not on post-category-pages or archive-pages. Maybe my question was not clear enough, sorry for that.
Is that achievable?Greets,
Luk- This reply was modified 8 years, 5 months ago by lukdol.
Hello @alichani!
THANK YOU, I think you nailed it! As for quick-test it works! I have to check it more intensive, when i got some more time, but i would say this is the correct answer!
Here the complete working code:
function wpb_lastupdated_posts() { // Get current post categories $cat_obj_array = get_the_category(); // Get first category's ID from WP_Term array $first_cat_id = $cat_obj_array[0]->term_id; // Query Arguments $lastupdated_args = array( 'orderby' => 'modified', 'ignore_sticky_posts' => '1', 'cat' => $first_cat_id, 'showposts' => 2 ); //Loop to display 5 recently updated posts $lastupdated_loop = new WP_Query( $lastupdated_args ); $counter = 1; $string = '<ul>'; while( $lastupdated_loop->have_posts() && $counter < 5 ) : $lastupdated_loop->the_post(); $string .= '<li><a href="' . get_permalink( $lastupdated_loop->post->ID ) . '"> ' .get_the_title( $lastupdated_loop->post->ID ) . '</a> ( '. get_the_modified_date('d.m,') . get_the_modified_time() .' ) </li>'; $counter++; endwhile; $string .= '</ul>'; return $string; wp_reset_postdata(); } //add a shortcode add_shortcode('lastupdated-posts', 'wpb_lastupdated_posts');I will set the status to resolved. One more time: many thanks, i searched for the solution for few days!