вывод последней записи на главной странице

Привет.

А как сделать вывод последней записи на главной странице?
И чтобы запись не вся была, а только n количество слов?

О.о получаешь массив постов, в цикле забиваешь пост в массив (один элемент – слово, разделитель – пробел), внутри этого цикла выводишь слова из созданного массива. всё пишется на php на одном дыхании

Андрей, это разве сложно? Если надо могу сорс навяйать..

Для меня сложно 🙂
Я php не знаю 🙂

Я почитал, по факам. Вот это оно? И будет на 2.3 работать?

<?php $temp_query = $wp_query; ?>
<?php query_posts(‘showposts=5’); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="shot_new">
<span class="date"><?php the_time(‘d.m.Y’) ?></span>
<h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
<?php the_excerpt(); ?>
</div>
<?php endwhile; ?>

аха, должен по крайней мере

Помогите с кодом

    <?php if (have_posts()) : ?>
    <?php $firstpostquery = new WP_Query('showposts=1'); ?>
    <?php while($firstpostquery->have_posts()) : $firstpostquery->the_post(); $firstpost = $post->ID; ?>
<div class="entry">
        <div class="post" id="post-<?php the_ID(); ?>">
            <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h1>
            <small>Написано: <?php the_time('d.m.Y') ?> | Раздел: <?php the_category(' &middot; ') ?> <?php if(function_exists('the_views')) { the_views(); } ?> </small>
                <div class="line"></div>

            
                <?php the_content('Read the rest of this entry &raquo;'); ?>
        

            <div class="postinfo"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?> <img src="<?php bloginfo('template_directory'); ?>/i/cm.gif" alt="comment" /> | Posted in &raquo; <?php the_category(', ') ?> <?php edit_post_link('| Edit', '', ' | '); ?> </div>
        </div>    
        
</div>
<div class="googleads1">
put your ads here
</div>
    <?php endwhile; ?>                                
    <?php endif; ?>

    <?php if (have_posts()) : ?>

        <?php $count=0; while (have_posts()) : the_post(); if(!($firstpost == $post->ID)) : ?>
        <?php if($count % 2 == 0) echo '<div class="left">'; else echo '<div class="right">'; ?>
        
            <div class="post" id="post-<?php the_ID(); ?>" style="">
                <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
                <small><abbr title="<?php the_time('Y-m-d\TH:i:sO'); ?>"><?php unset($previousday); printf(__('%1$s &#8211; %2$s'), the_date('', '', '', false), get_the_time()) ?></abbr> <!-- by <?php the_author() ?> --></small>
<div class="clear"></div>
            
                    <p><?php the_content_rss('', TRUE, '', 30) ; ?></p><div class="clear"></div>
                    
        
            </div>
        </div>
        <?php if($count % 2 != 0) echo '<div class="clear"></div>';?>

        <?php $count++; endif; ?>

Это код главной страницы сайта. Он выводит 1-й пост, потом идёт рекламное место, а потом остальные посты.

Что сделать, чтобы выводилось не больше 3 постов?

Проще надо быть. 🙂

<?php query_posts('showposts=3'); ?>
<?php if (have_posts()) : ?>
<?php the_post();?>
<div class="entry">
        <div class="post" id="post-<?php the_ID(); ?>">
            <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h1>
            <small>Написано: <?php the_time('d.m.Y') ?> | Раздел: <?php the_category(' &middot; ') ?> <?php if(function_exists('the_views')) { the_views(); } ?> </small>
                <div class="line"></div>

            
                <?php the_content('Read the rest of this entry &raquo;'); ?>
        

            <div class="postinfo"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?> <img src="<?php bloginfo('template_directory'); ?>/i/cm.gif" alt="comment" /> | Posted in &raquo; <?php the_category(', ') ?> <?php edit_post_link('| Edit', '', ' | '); ?> </div>
        </div>    
        
</div>
<div class="googleads1">
put your ads here
</div>

<?php the_post();?>
<div class="left">
        
            <div class="post" id="post-<?php the_ID(); ?>" style="">
                <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
                <small><abbr title="<?php the_time('Y-m-d\TH:i:sO'); ?>"><?php unset($previousday); printf(__('%1$s - %2$s'), the_date('', '', '', false), get_the_time()) ?></abbr> <!-- by <?php the_author() ?> --></small>
<div class="clear"></div>
            
                    <p><?php the_content_rss('', TRUE, '', 30) ; ?></p>
        
<?php the_post();?>
<div class="right">
        
            <div class="post" id="post-<?php the_ID(); ?>" style="">
                <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
                <small><abbr title="<?php the_time('Y-m-d\TH:i:sO'); ?>"><?php unset($previousday); printf(__('%1$s - %2$s'), the_date('', '', '', false), get_the_time()) ?></abbr> <!-- by <?php the_author() ?> --></small>
<div class="clear"></div>
            
                    <p><?php the_content_rss('', TRUE, '', 30) ; ?></p><div class="clear"></div>
                    
        
            </div>
        </div>

<?php endif; ?>

Ну, с DIVами уже сами как-нибудь разберетесь.

Гы. Спасибо 🙂

Я сам код не придумывал 🙂
=======
Обновил.
всё работает.

Вообще-то код для морды лучше не в index.php, а в home.php класть. А ошибку дает else, оставшийся от прошлой жизни.

И вообще, как бы Вы не упирались, разобраться с php придется. Поверьте, ничего там военного нет. По крайней мере, в той части, которая нужна для тюнинга тем.

Я уже книгу заказал, с понедельника должны привезти 🙂

Anonymous
Отправить
Ответ на: