• Resolved mm88

    (@mm88)


    Hi guys, I would insert in my home page – and only in my home page – a table containing only the LAST post tagged as “highlights”.

    before the container main code, I could put a div like this:

    <div class="news">
    <table width="100%">
    <tr valign="top">
    
    <td align="left">
    ?????????????????????????????????????????
    </td>
    
    </tr>
    </table>
    </div>

    but what about the php code to visualize the div only in the home and only tha last post with a specific tag?

    many thanks for helping

Viewing 9 replies - 1 through 9 (of 9 total)
  • if you want to have the div only in your home, you have to put it on in the home.php (in your theme)

    To visualize only a specific post, I think you should use query_posts

    [maybe not the best answer]

    Thread Starter mm88

    (@mm88)

    Thanks for your reply, but I’ve used <?php get_posts('arguments'); ?> outside the loop.

    About the div, if I put it in the index.php page before the loop, it will appear in all pages. But I would see the div only in the home page.

    Maybe is necessary a control IF

    Any suggestion?

    thanks

    http://codex.wordpress.org/Function_Reference/query_posts#Tag_Parameters

    would help you call a post by a specific tag

    http://codex.wordpress.org/Conditional_Tags#The_Main_Page

    is_front_page (or mayb is_home) conditional will help with other request

    only in the home page >>> use the page “home.php”, not “index.php”
    If you don’t want use this… ( look in the codex ) is_home() returns a boolean (true if the page is the home)

    Thread Starter mm88

    (@mm88)

    Thanks guys.

    I’ve a still a problem withe is_home() conditional case:

    I’m using this code to display a specific post only in the home:

    <?php
    global $post;     // outside the loop
    
    if ( is_home() ) {
    
     $postslist = get_posts('numberposts=1&date=ASC&category_name=Highlights');
     foreach ($postslist as $post) :
        setup_postdata($post);   
    
    } else {
        // This is not the home
    }
    
    ?>

    but the system returns the error Parse error: syntax error, unexpected ‘}’ in…

    why?

    thanks

    foreach is not closed
    try

    foreach ($postslist as $post) :
        setup_postdata($post);
    endforeach;

    or

    foreach ($postslist as $post) { setup_postdata($post);}
    Thread Starter mm88

    (@mm88)

    Many thanks for your reply, but trying your code, the system writes me:

    Parse error: syntax error, unexpected T_ENDFOREACH in

    where is the error?

    thanks again

    <?php
    global $post;     // outside the loop
    
    if ( is_home() ) {
    
     $postslist = get_posts('numberposts=1&date=ASC&category_name=Highlights');
     foreach ($postslist as $post) :
        setup_postdata($post);
    endforeach;
    } else {
        // This is not the home
    }
    
    ?>

    I don’t think there is any error inside this part of the code =p
    I may be wrong

    Thread Starter mm88

    (@mm88)

    yep, sorry, there was another endforeach;

    the code is correct and works perfectly:

    <?php
    global $post;     // outside the loop
    
    if ( is_home() ) {
    
     $postslist = get_posts('numberposts=1&date=ASC&category_name=Highlights');
     foreach ($postslist as $post) :
        setup_postdata($post);
    endforeach;
    } else {
        // This is not the home
    }
    
    ?>

    Thanks!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Put an element only in the main page’ is closed to new replies.