Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Display Recent Article Title to Top New Bar of PHP WordPress Site from Specific ID

    • 0
    • 0
    • 0
    • 2
    • 0
    • 0
    • 0
    • 754
    Answer it

    Hello

    I recently stumbled upon this site and was wondering if someone out there could provide help.

     

    Currently there is an area in the top bar of my Wordpress site that has a section called "BREAKING" (this "BREAKING" word can be edited in the admin page) ...and then the most popular articles's title/links rotate in next to the word "BREAKING".  See screengrab below for reference:

     

    Instead of displaying "the most popular articles' title/links", I am looking to do either of these options:

     

    1) display the most recent articles title/links from a specific category ID

    2) display a title/link from one specific post (based on post ID?)

     

    I have attached the .php file for this "top bar" for reference.  I feel the update would be around line 73, but am not entirely sure.

     

    Is there anyone out there who may be able to provide further guidance?

     

    thank you
    Matt

     

     

     

     

     

 2 Answer(s)

  •  Hello Matt

    For option 1:-

    you can filter the posts by this code below, please put the code in the file where you are fetching posts :-
     
    <?php $args = array(
    	'posts_per_page'   => 5,
    	'offset'           => 0,
    	'category'         => 3, // Put the ID of category for which the posts you need
    	'category_name'    => '',
    	'orderby'          => 'date',
    	'order'            => 'DESC',
    	'include'          => '',
    	'exclude'          => '',
    	'meta_key'         => '',
    	'meta_value'       => '',
    	'post_type'        => 'post',
    	'post_mime_type'   => '',
    	'post_parent'      => '',
    	'author'	       => '',
    	'author_name'	   =>'',
        'post_status'      => 'publish',
    	'suppress_filters' => true 
    );
    $posts_array = get_posts( $args ); ?>
    
    I hope I answered your question, Let me know, if this works 
    
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: