這個簡碼顯示我的主頁上的最後一個X(從最新到最舊排序)帖子。我想選擇哪一個我想通過ID顯示。怎麼做?如何只包括選擇的帖子(通過ID) - WordPress的簡碼
我有一個簡碼,看起來像這樣
這是輸入:
if(!empty($blog)){
echo do_shortcode('[blog item_number=4]');
}
這是此簡碼的代碼。
function beau_blog($atts, $content = null, $code = '')
{
global $imgsize;
extract(shortcode_atts(array(
'post_not_in' => '',
'item_number' => '4',
\t
), $atts));
$loop = new WP_Query('&posts_per_page=' . $item_number);
?>
<section class="beau-blog stretch-layout">
<div class="blog-title"><?php echo get_post_meta(get_the_ID(), '_page_blog_text', TRUE); ?></div>
<div class="blog-content"><?php echo get_post_meta(get_the_ID(), '_page_blog_des', TRUE); ?></div>
<?php if ($loop->have_posts()) : ?>
<div class="blog-lists">
<?php $i = 0;
while ($loop->have_posts()) : $loop->the_post();
$featuredID = wp_get_attachment_image_src(get_post_thumbnail_id(), 'single-post-thumbnail');
$date = strtotime(get_the_date());
if ($i % 2 != 0) {
?>
<div class="row-fluid">
<div class="span6 blog-odd hover-img beau-animated move-to-right">
<?php beau_resizer($featuredID[0], $imgsize['blog']['w'], $imgsize['blog']['h'], true, get_the_title(get_the_ID())); ?>
</div>
<div class="span6 blog-odd-r beau-animated move-to-left">
<div class="odd-bg"></div>
<div class="content">
<h3><?php the_title(); ?></h3>
<div class="date"><?php echo date('l', $date).' '.date('j', $date).' '.date('F ', $date).' '.date('Y ', $date); ?></div>
<div class="blog-description"><?php echo beau_excerpt(54); ?></div>
</div>
</div>
</div>
<?php
} else {
?>
<div class="row-fluid bg-r">
<div class="span6 blog-even-l beau-animated move-to-right">
<div class="odd-bg"></div>
<div class="content">
<h3><?php the_title(); ?></h3>
<div class="date"><?php echo date('l', $date).' '.date('j', $date).' '.date('F ', $date).' '.date('Y ', $date); ?></div>
<div class="blog-description"><?php echo beau_excerpt(54); ?></div>
</div>
</div>
<div class="span6 blog-odd hover-img beau-animated move-to-left">
--------
<?php beau_resizer($featuredID[0], $imgsize['blog']['w'], $imgsize['blog']['h'], true, get_the_title(get_the_ID())); ?>
----------
</div>
</div>
<?php
}
?>
<?php $i++; endwhile; ?>
</div>
<?php
wp_reset_postdata();
endif;
?>
</section>
<?php
$out = ob_get_contents();
ob_end_clean();
return $out;
}
add_shortcode('blog', 'beau_blog');
function beau_blog_style2($atts, $content = null, $code = '')
{
global $imgsize;
extract(shortcode_atts(array(
'post_not_in' => '',
'item_number' => '4'
), $atts));
$loop = new WP_Query('&posts_per_page=' . $item_number);
?>
<section class="beau-blog stretch-layout style2">
<div class="blog-title"><?php echo get_post_meta(get_the_ID(), '_page_blog_text', TRUE); ?></div>
<?php if ($loop->have_posts()) : ?>
<div class="blog-lists blog-lists-full-layout">
<?php $i = 0;
while ($loop->have_posts()) : $loop->the_post();
$featuredID = wp_get_attachment_image_src(get_post_thumbnail_id(), 'single-post-thumbnail');?>
<div class="row-fluid">
<div class="blog-list-container">
<div class="span12 beau-animated fade-in">
<div class="full-content">
<div class="row-fluid">
<div class="span1">
<div class="date"><span><?php echo get_the_time('d') ?></span></div>
<div class="month-year">
<span><?php echo substr(get_the_time('F'), 0, 3); ?></span></div>
</div>
<div class="span11">
<a href="<?php echo get_permalink() ?>"><h3><?php the_title(); ?></h3></a>
<div class="content style2">
<?php beau_excerpt(30, true); ?>
</div>
</div>
</div>
<div class="row-fluid">
<a href="<?php echo get_permalink() ?>">
<div class="post-thumb hover-img">
<!-- <img src="--><?php //echo $featuredID[0] ?><!--"-->
<!-- alt="--><?php //echo get_the_title(); ?><!--">-->
<?php beau_resizer($featuredID[0], $imgsize['blog2']['w'], $imgsize['blog2']['h'], true, get_the_title()); ?>
</div>
</a>
</div>
</div>
</div>
</div>
</div>
<?php $i++; endwhile;
?>
</div>
<?php
wp_reset_postdata();
endif;
?>
</section>
<?php
$out = ob_get_contents();
ob_end_clean();
return $out;
}
add_shortcode('blog_style2', 'beau_blog_style2');
function beau_attendingform($atts, $content = null, $code = '')
{
?>
<section class="beau-attending-form">
<h2 class="attending-title"><?php echo get_post_meta(get_the_ID(), '_page_attending_text', TRUE); ?></h2>
<div class="attending-content"><?php echo get_post_meta(get_the_ID(), '_page_attending_des', TRUE); ?></div>
<div class="row-fluid">
<?php $rand = uniqid();
ob_start(); ?>
<script type="text/javascript">
jQuery(function ($) {
$('#contact_<?php echo $rand; ?>').submit(function() {
$('#loading_contact_<?php echo $rand; ?>').fadeIn('fast');
$('#result_contact_<?php echo $rand; ?>').hide();
$.ajax({
type: 'POST',
url: $(this).attr('action'),
data: $(this).serialize(),
success: function (data) {
$('#result_contact_<?php echo $rand; ?>').html(data);
$('#result_contact_<?php echo $rand; ?>').fadeIn('fast');
$('#loading_contact_<?php echo $rand; ?>').hide();
}
})
return false;
});
});
</script>
<form id="contact_<?php echo $rand; ?>"
action="<?php echo BEAU_BASE_URL . '/include/scripts/attending.php'; ?>" method="post"
class="span12 attending">
<!-- <form id="contact_--><?php //echo $rand; ?><!--" action="-->
<?php //echo BEAU_BASE_URL .'/include/scripts/contact.php'; ?><!--" method="post">-->
\t \t <input type="text" name="fullname" placeholder="Jak się nazywasz?" class="span12">
<input type="text" name="email" placeholder="Email" class="span12">
\t \t <input type="text" name="persons_attending" placeholder="Temat" class="span12">
<textarea class="span12" name="wedding_ceremony" rows="8" placeholder="Tu wpisz wiadomość"></textarea>
<input type="submit" class="btn" name="submit" value="<?php _e('Naciśnij by wysłać', 'beau'); ?>"
id="contact-submit"/>
<input type="hidden" name="send_to" value="<?php echo $send_to; ?>"/>
<!-- <a href="#" class="btn">I’M ATTENDING</a>-->
<div id="result_contact_<?php echo $rand; ?>"></div>
<div id="loading_contact_<?php echo $rand; ?>" style="margin-bottom: 20px; display: none;"></div>
</form>
</div>
</section>
<?php
$out = ob_get_contents();
ob_end_clean();
return $out;
}
add_shortcode('attendingform', 'beau_attendingform');
function beau_attendingform_style2($atts, $content = null, $code = '')
{
?>
<section class="beau-attending-form style2">
<h2 class="attending-title"><?php echo get_post_meta(get_the_ID(), '_page_attending_text', TRUE); ?></h2>
<div class="row-fluid">
<?php $rand = uniqid();
ob_start(); ?>
<script type="text/javascript">
jQuery(function ($) {
$('#contact_<?php echo $rand; ?>').submit(function() {
$('#loading_contact_<?php echo $rand; ?>').fadeIn('fast');
$('#result_contact_<?php echo $rand; ?>').hide();
$.ajax({
type: 'POST',
url: $(this).attr('action'),
data: $(this).serialize(),
success: function (data) {
$('#result_contact_<?php echo $rand; ?>').html(data);
$('#result_contact_<?php echo $rand; ?>').fadeIn('fast');
$('#loading_contact_<?php echo $rand; ?>').hide();
}
})
return false;
});
});
</script>
<form id="contact_<?php echo $rand; ?>"
action="<?php echo BEAU_BASE_URL . '/include/scripts/attending.php'; ?>" method="post"
class="span12 attending">
<div class="f-bg"></div>
<div class="f-bg-left-top"></div>
<div class="f-bg-right-top"></div>
<div class="f-bg-left-bottom"></div>
<div class="f-bg-right-bottom"></div>
<input type="text" name="fullname" placeholder="Fullname" class="span12">
<input type="text" name="email" placeholder="Email" class="span12">
<input type="submit" class="btn" name="submit" value="<?php _e('Wysyłam wiadomość!', 'beau'); ?>"
id="contact-submit"/>
<input type="hidden" name="send_to" value="<?php echo $send_to; ?>"/>
<div id="result_contact_<?php echo $rand; ?>"></div>
<div id="loading_contact_<?php echo $rand; ?>" style="margin-bottom: 20px; display: none;"></div>
</form>
</div>
</section>
<?php
$out = ob_get_contents();
ob_end_clean();
return $out;
}
add_shortcode('attendingform_style2', 'beau_attendingform_style2');
function beau_button($atts, $content = null)
{
extract(shortcode_atts(array(
'icon' => '',
'size' => 'small',
'color' => '',
'url' => '#'
), $atts));
$attstoclass = '';
if (!empty($icon)) $attstoclass = '<i class="' . $icon . '"></i>';
$out = '<a class="st-button ' . $size . ' ' . $color . '" href="' . $url . '">' . $attstoclass . strip_tags($content) . '</a>';
return $out;
}
網址是:nikosis.mzonespace.co.uk