• Resolved webcatsanddogs

    (@webcatsanddogs)


    The homepage for my client’s new WordPress site is filled mostly with static content. There is one spot, however, where the most recent post in a certain category (“news”) needs to be displayed. I understand how to create the news category, and add posts to the category.

    What I am hoping someone can possibly help with is figuring out what code to put into the home page template in the spot where the most recent post of a certain category is supposed to appear.

    Here is a link to the site in progress.

    If you scroll to the bottom, you can see the spot where the most recent post and its parts need to be displayed.

    Here is what the template looks like now, in the area where the most recent post needs to go.

    <div class="section group">
    	<div class="col span_1_of_2" id="extra1">
    		<div id="featuredNewsSectionTitle">
    			Featured News
    		</div>
    		<div id="featuredNewsSectionPhoto col">
    			<img id="featuredNewsSectionPhoto" src="https://dansdemos.info/prelaunch/WorldClothingCorp_0705/wp-content/themes/WorldClothing354/images/featuredNewsPhoto.png">
    		</div>
    		<div id="featuredNewsHeadline">
    			July 7<sup>th</sup> WordPress Challenge!
    		</div>
    		<div id="featuredNewsCommentCount">
    			3 comments
    		</div>
    		<div id="featuredNewsDate">
    			July 7, 2013
    		</div>
    		<div id="featuredNewsLedeText">
    			Featured News displayed in the lower left corner of the home page.  This will be the most recent
    			post in WordPress, with a category of News, including text, photo, title, date, number of comments,
    			and a 'read more' link.
    			<br><br>
    			<b>The WordPress challenge</b> is:  What code goes into the home-page template in this spot, to show the
    			latest post in the news category from the WordPress database?  This text here is hard-coded into
    			the home-page template,  I am hoping there might be some WordPress/PHP that can go into this spot.
    		</div>
    		<div id="featuredNewsReadMoreLink">
    			Read more
    		</div>
    	</div>
    	<div class="col span_1_of_2" id="extra2">
    		<img src="https://dansdemos.info/prelaunch/WorldClothingCorp_0705/wp-content/themes/WorldClothing354/images/markets.png">
    	</div>
    </div>

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter webcatsanddogs

    (@webcatsanddogs)

    I think I figured out what to do. This looks like it is all about template tags.

    Thread Starter webcatsanddogs

    (@webcatsanddogs)

    The more I learn about template tags, the more it seems that what I am looking for are the right template tags.

    Please do not hesitate to comment with suggestions, comments, or questions.

    I heard this great slogan:

    You cannot do it. I cannot do it. But, we can do it.

    This board helps a lot, even if it is just a place to organize my confusion. ??

    When I have the right template tags, I will post the solution here, with a link to the live implementation.

    Thread Starter webcatsanddogs

    (@webcatsanddogs)

    Template tags are WordPress’s functions for retrieving data from the WordPress database. They appear to be implemented with some of the best, most elegant and useful open-source programming I have seen. I think I am going to start loving WordPress, now that I can start using template tags.

    Today, I am working the template tags into my project, to solve the question starting this thread. Will post link to solution then mark thread resolved.

    Thread Starter webcatsanddogs

    (@webcatsanddogs)

    Solution implemented/demo at this link. Code to get the most recent post of a category:

    $args = array(
    	'posts_per_page'  => 1,
    	'offset'          => 0,
    	'category_name'   => 'news',
    	'orderby'         => 'post_date',
    	'order'           => 'DESC',
    	'post_type'       => 'post',
    	'post_status'     => 'publish',
    	'suppress_filters' => true )
    ;
    $posts_array = get_posts($args);
    //showArray($posts_array);
    
    foreach( $posts_array as $post ) : setup_postdata($post); ?>
    	<li>
              <?php the_title(); ?>
        </li>
    	<li>
              <?php
              remove_filter ('the_content', 'wpautop');
              the_content();
              ?>
         </li>
    <?php endforeach; ?>

    Hey webcatsanddogs, congrats on getting it yourself before anyone could even get to helping you! ??

    Thread Starter webcatsanddogs

    (@webcatsanddogs)

    Thanks.. sometimes, have to buckle down and figure something out. Sounds like you know how that is.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Put Most Recent Post in Certain Category Into a Spot on Template’ is closed to new replies.