ThemeShaper Forums » Thematic

[closed]

Display two posts on my static "Front page"

(7 posts)
  • Started 4 years ago by Baudesign
  • Latest reply from Baudesign
  • This topic is not resolved
  1. Baudesign
    Member

    I am almost there, and would like to thank those who have helped me so far build my new child theme.

    Now, here is my problem: I am building a static "Front page" that will display, horizontally: a slideshow, then the latest two posts written, a sponsors' area, then 3 popular articles before the footer: http://www.mulibwanji.com/ma/

    "Presse & Reviews" will be my main blog page.

    I am trying to achieve, through functions, something like:

    if is_front_page(), then show the latest, and only the latest, two posts (I will style them differently later on thanks to the p1 and p2 classes generated by thematic).

    Not only I do not know how to create this function (I am so bad at php programming!), but from what I see, this code would have to be included in the page content, something I really do not want.

    Perhaps, one would have to remove the #content <div> before including the new one for the two articles. Not sure.

    If you can help, I am ready to Google a solution.

    Thanks

    Pat

    Posted 4 years ago #
  2. Baudesign
    Member

    Okay, here is a little update on my quest.

    1. I created a template file.
    2. In this template file, I included this code:

    <?php
    /*
    Template Name: Diaporama
    */
    ?>
    <?php get_header() ?>
    
    <div id="container" class="feature">
      <div id="content">
        <div id="latest-two">
          <?php $lastposts = get_posts('numberposts=2');
     		foreach($lastposts as $post) :
        	setup_postdata($post); ?>
          	<div id="post-<?php the_ID() ?>" class="<?php thematic_post_class() ?>">
            	<?php thematic_postheader(); ?>
            	<div class="entry-content">
              	<?php thematic_content(); ?>
              	<?php wp_link_pages('before=<div class="page-link">' .__('Pages:', 'thematic') . '&after=</div>') ?>
            </div>
    
          </div><!-- .post -->
          <?php endforeach; ?>
        </div><!-- #latest-two -->
        <div id="sponsors">
        Sponsors
        </div><!-- #sponsors -->
        <div id="popular">
        Popular
        </div><!-- #popular -->
      </div>
      <!-- #content -->
    </div>
    <!-- #container .feature -->
    <?php get_footer() ?>

    It works... partially :-(

    If you look at the generated code, you notice that thematic is kept out of the loop: it does not generate any classe or any id, leaving me with no options for styling.

    Pff!

    Pat

    Posted 4 years ago #
  3. Baudesign
    Member

    [Please disregard the post before as I updated a second too late]

    ...second update, for those who might be interested:

    <div id="latest-two">
          <?php
     $lastposts = get_posts('numberposts=2');
     foreach($lastposts as $post) :
        setup_postdata($post);
     ?>
          <div id="post-<?php the_ID() ?>" class="<?php thematic_post_class() ?>">
            <?php thematic_postheader(); ?>
            <div class="entry-content">
              <?php thematic_content(); ?>
              <?php wp_link_pages('before=<div class="page-link">' .__('Pages:', 'thematic') . '&after=</div>') ?>
            </div>
            <?php thematic_postfooter(); ?>
          </div><!-- .post -->
          <?php endforeach; ?>
        </div><!-- #latest-two -->

    It seems to work so far. But the titles don't display as links. And the "read more" cut does not show.

    Posted 4 years ago #
  4. Tina
    Member

    Hi,

    I'm actually working on something that's similar. This modified code that I found posted in the forums (thanks to the Agricultural post), works on Thematic but I'm using a Child Theme so I'm not sure if this will work directly on yours:

    function latest_post() {
    
    	echo "<div id='newsgrab'>";
    		$posts_latest = get_posts("showposts=2");
    		if( $posts_latest ) {
            	foreach( $posts_latest as $post_n ) {
    			setup_postdata( $post_n );
    			echo '<h2><a href="';
    			 echo (get_permalink($post_n->ID));
    			  echo '" title="Permanent Link to ';
    			   echo (get_the_title($post_n->ID));
    			    echo '">' ;
    			     echo (get_the_title($post_n->ID));
    			      echo '</a></h2>';
    	the_content("Continue reading '" . the_title('', '', false) . "'");
    				}
    			}
    	echo "</div>";
    
    	}
    add_action ('thematic_indexloop','latest_post');

    I'm not sure how you would apply it to your code but you are missing "<a href" tags for you Titles to display as links.

    I'm not sure about read more, the same idea might apply.

    Posted 4 years ago #
  5. Baudesign
    Member

    @Tina,

    Your function does not work because it substitutes itself for the loop thematic_indexloop. The loop, as it is, when I browse the "Presse & Reviews" section is fine... for the moment.

    What I am trying to achieve is display, on the static "Front Page", the two latest articles (Posts) written in the blog, with a title link that links to the corresponding single page.

    Posted 4 years ago #
  6. Tina
    Member

    I'm sorry I didn't realise you were working on template file.

    I put this in in the functions.php and for me, it actually does work, but as I said I'm using the Gallery Child Theme.

    I hope you find your solution.

    Posted 4 years ago #
  7. Baudesign
    Member

    I found a way display the titles as permalinks, but I have the feeling that it is the wrong way:

    I copied and pasted the code found in the content-extension.php file, by adding this condition != is_page('accueil') like so:

    // Information in Post Header
    function my_thematic_postheader() {
        global $id, $post, $authordata;
    
        // Create $posteditlink
        $posteditlink .= '<a href="' . get_bloginfo('wpurl') . '/wp-admin/post.php?action=edit&amp;post=' . $id;
        $posteditlink .= '" title="' . __('Edit post', 'thematic') .'">';
        $posteditlink .= __('Edit', 'thematic') . '</a>';
        $posteditlink = apply_filters('thematic_postheader_posteditlink',$posteditlink); 
    
        if (is_single() || is_page() != is_page('accueil')) {
            $posttitle = '<h1 class="entry-title">' . get_the_title() . "</h1>\n";
        } elseif (is_404()) {
            $posttitle = '<h1 class="entry-title">' . __('Not Found', 'thematic') . "</h1>\n";
        } else {
    
    <-- bla bla bla bla bla -->
    
        echo apply_filters( 'my_thematic_postheader', $postheader ); // Filter to override default post header
    } // end my_thematic_postheader

    ...renaming thematic_postheader with my_thematic_postheader.

    Then in my template file:

    <div id="latest-two">
          <?php $lastposts = get_posts('numberposts=2');
     		foreach($lastposts as $post) :
        	setup_postdata($post); ?>
          	<div id="post-<?php the_ID() ?>" class="<?php thematic_post_class() ?>">
            	<?php my_thematic_postheader(); ?>
            	<div class="entry-content">
              	<?php thematic_content(); ?>
              	<?php wp_link_pages('before=<div class="page-link">' .__('Pages:', 'thematic') . '&after=</div>') ?>
            </div>
    
          </div><!-- .post -->
          <?php endforeach; ?>
        </div><!-- #latest-two -->

    There must be some way to simplify the function my_thematic_postheader

    Thanks for any tips.

    Posted 4 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.