我做了一个名为'足球'(单数)'足球'(复数)的新职位类型。我有一个短代码,可以在一个页面中显示我的所有帖子,其中包含特色图片,例如:http://www.freebetnodeposit.org/match-reports/但有人可以帮我修改此代码,这样就不会显示“帖子”,而是显示来自'足球的帖子'发布类型。
下面是代码:
<?php
function gp_posts($atts, $content = null) {
extract(shortcode_atts(array(
'name' => '',
'cats' => '',
'images' => 'true',
'image_width' => '533',
'image_height' => '200',
'image_wrap' => 'false',
'cols' => '2',
'per_page' => '6',
'link' => 'both',
'orderby' => 'date',
'order' => 'desc',
'offset' => '0',
'content_display' => 'excerpt',
'excerpt_length' => '400',
'title' => 'true',
'title_size' => '',
'title_font' => '',
'title_length' => '500',
'meta' => 'true',
'meta_author' => 'true',
'meta_date' => 'true',
'meta_cats' => 'true',
'meta_tags' => 'true',
'score' => 'true',
'read_more' => 'true',
'pagination' => 'true',
'spacing' => 'spacing-normal',
'header' => '',
'rss' => '',
'color' => ''
),$atts));
global $wp_query, $post, $dirname, $gp_settings;
require(gp_inc . 'options.php');
// Order By
if($orderby == 'score') {
$orderby = 'meta_value_num';
$meta_key = '_'.$dirname.'_total_score';
} else {
$orderby = $orderby;
$meta_key = '';
}
// Title Size
$title_weight = '';
if($title_size != "") {
if(preg_match('/^1[0-4]$/', $title_size)) {
$title_weight = 'font-weight: bold; ';
}
}
if($title_size != "") {
if(preg_match('/%/', $title_size) OR preg_match('/em/', $title_size) OR preg_match('/px/', $title_size)) {
$title_size = 'font-size: '.$title_size.'; ';
} else {
$title_size = 'font-size: '.$title_size.'px; ';
}
} else {
$title_size = "";
}
// Title Font
if($title_font != "") {
$title_font = 'font-family: '.$title_font.'; ';
} else {
$title_font = "";
}
// Pagination
if (get_query_var('paged')) {
$paged = get_query_var('paged');
} elseif (get_query_var('page')) {
$paged = get_query_var('page');
} else {
$paged = 1;
}
// Post Query
$args=array(
'post_type' => 'post',
'post_status' => 'publish',
'category_name' => $cats,
'paged' => $paged,
'ignore_sticky_posts' => 0,
'orderby' => $orderby,
'order' => $order,
'meta_key' => $meta_key,
'posts_per_page' => $per_page,
'offset' => $offset
);
$featured_query = new wp_query($args); $counter = "";
ob_start(); ?>
<!-- BEGIN POST WRAPPER -->
<div class="post-wrapper <?php echo $name.' '.$spacing; ?>">
<!-- BEGIN HEADER -->
<?php if($header) { ?><h3 class="featured-header" style="border-color: <?php echo $color; ?>;"><?php echo $header; ?><?php if($rss) { ?><a href="<?php echo $rss; ?>" class="icon-rss"></a><?php } ?></h3><?php } ?>
<!-- END HEADER -->
<?php while ($featured_query->have_posts()) : $featured_query->the_post(); $counter = $counter + 1;
// Image Dimensions
if(get_post_meta($post->ID, '_'.$dirname.'_thumbnail_width', true) && get_post_meta($post->ID, '_'.$dirname.'_thumbnail_width', true)) {
$image_width = get_post_meta($post->ID, '_'.$dirname.'_thumbnail_width', true);
} else {
$image_width;
}
if(get_post_meta($post->ID, '_'.$dirname.'_thumbnail_height', true) && get_post_meta($post->ID, '_'.$dirname.'_thumbnail_height', true)) {
$image_height = get_post_meta($post->ID, '_'.$dirname.'_thumbnail_height', true);
} else {
$image_height;
}
// Image Dimensions For Mobiles
if($image_width <= 460 && get_option($dirname.'_responsive') == "0") {
$image_ratio = 460 / $image_width;
$new_image_width = $image_width * $image_ratio;
$new_image_height = $image_height * $image_ratio;
} else {
$new_image_width = $image_width;
$new_image_height = $image_height;
}
// Columns
if($counter %$cols == 1) {
$first_column = " first-column ";
} else {
$first_column = "";
}
if($cols > 1) {
$columns = " post-columns ";
} else {
$columns = "";
}
$col_width = (100 - (($cols -1) * 4)) / $cols;
// Total Score
if(get_post_meta($post->ID, '_'.$dirname.'_total_score', true) > 0) {
$total_score_width = (get_post_meta($post->ID, '_'.$dirname.'_total_score', true) / $gp_settings['star_number']) * 100;
} else {
$total_score_width = 0;
}
?>
<!-- BEGIN POST -->
<div <?php post_class('post-loop'.$first_column.$columns); ?> style="width: <?php echo $col_width; ?>%;">
<!-- BEGIN IMAGE -->
<?php if(has_post_thumbnail() && $images == "true") { ?>
<div class="post-thumbnail<?php if($image_wrap == "true") { ?> wrap<?php } ?>">
<?php if(($link == "image" OR $link == "both") && get_post_meta($post->ID, '_'.$dirname.'_link_type', true) != "None") { ?>
<a href="<?php if(get_post_meta($post->ID, '_'.$dirname.'_link_type', true) == "Lightbox") { if(get_post_meta($post->ID, '_'.$dirname.'_custom_url', true)) { echo get_post_meta($post->ID, '_'.$dirname.'_custom_url', true); } else { echo wp_get_attachment_url(get_post_thumbnail_id($post->ID)); }} else { if(get_post_meta($post->ID, '_'.$dirname.'_custom_url', true)) { echo get_post_meta($post->ID, '_'.$dirname.'_custom_url', true); } else { the_permalink(); }} ?>"<?php if(get_post_meta($post->ID, '_'.$dirname.'_link_type', true) == "Lightbox") { ?> rel="prettyPhoto[<?php echo $name; the_ID(); ?>]"<?php } ?>>
<?php } ?>
<?php $image = aq_resize(wp_get_attachment_url(get_post_thumbnail_id($post->ID)), $new_image_width, $new_image_height, true, true); ?>
<?php if(get_post_meta($post->ID, '_'.$dirname.'_link_type', true) == "Lightbox") { ?>
<span class="lightbox-hover icon-plus"></span>
<?php } ?>
<img src="<?php echo $image; ?>" width="<?php echo $image_width; ?>" alt="<?php if(get_post_meta(get_post_thumbnail_id(), '_wp_attachment_image_alt', true)) { echo get_post_meta(get_post_thumbnail_id(), '_wp_attachment_image_alt', true); } else { echo get_the_title(); } ?>" />
<?php if(($link == "image" OR $link == "both") && get_post_meta($post->ID, '_'.$dirname.'_link_type', true) != "None") { ?></a><?php } ?>
</div>
<?php if($image_wrap == "false") { ?><div class="clear"></div><?php } ?>
<?php } ?>
<!-- END POST -->
<!-- BEGIN LIGHTBOX IMAGES -->
<?php $args = array('post_type' => 'attachment', 'post_parent' => $post->ID, 'numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'asc', 'post__not_in' => array(get_post_thumbnail_id())); $attachments = get_children($args); if($attachments) { foreach ($attachments as $attachment) { ?>
<a href="<?php if(get_post_meta($attachment->ID, '_gp_video_url', true)) { ?>file=<?php echo get_post_meta($attachment->ID, '_gp_video_url', true); } else { echo wp_get_attachment_url($attachment->ID); } ?>" rel="prettyPhoto[<?php echo $name; the_ID(); ?>]" title="<?php echo $attachment->post_content; ?>" style="display: none;"><img src="" alt="<?php echo $attachment->post_title; ?>"></a>
<?php }} ?>
<!-- END LIGHTBOX IMAGES -->
<!-- BEGIN POST TEXT -->
<div class="post-text"<?php if(has_post_thumbnail() && $images == "true" && $image_wrap == "true") { ?> style="margin-left: <?php echo $image_width + 20; ?>px;"<?php } ?>>
<!-- BEGIN TITLE -->
<?php if($title == "true") { ?><h2 style="margin-top:-10px;"><?php if($link == "title" OR $link == "both") { ?><a href="<?php the_permalink(); ?>" title="<?php echo the_title_limit($title_length); ?>"><?php } ?><?php echo stripslashes(do_shortcode(get_post_meta($post->ID, '_'.$dirname.'_hometeamname', true))); ?> VS <?php echo stripslashes(do_shortcode(get_post_meta($post->ID, '_'.$dirname.'_awayteamname', true))); ?><?php if($link == "title" OR $link == "both") { ?></a><?php } ?></h2><?php } ?>
<!-- END TITLE -->
<!-- BEGIN SCORE META -->
<?php if($score == "true" && get_post_meta($post->ID, '_'.$dirname.'_total_score', true) > 0) { ?>
<div class="score-meta">
<span class="gp-stars-wrapper" style="width: <?php echo (19.6 * $gp_settings['star_number']); ?>px;"><span class="rating-unselected"><span class="rating-selection" style="width:<?php echo $total_score_width; ?>%"></span></span></span>
</div>
<?php } ?>
<!-- END SCORE META -->
<!-- BEGIN POST META-->
<?php if($meta == "true" && ($meta_date == "true" OR $meta_author == "true" OR $meta_cats == "true")) { ?>
<div class="post-meta">
<?php if($meta_date == "true" OR $meta_author == "true" OR $meta_cats == "true") { ?>
<?php if($meta_date == "true") { ?><span class="meta-date">Match Date: <?php the_time(get_option('date_format')); ?></span><?php } ?>
<br />
<?php if($meta_cats == "true") { ?><span class="meta-cats">Game Type: <?php the_category(', '); ?></span><?php } ?>
<?php } ?>
</div>
<?php } ?>
<!-- END POST META-->
<!-- BEGIN POST CONTENT -->
<?php if($content_display == "full") { ?>
<?php } else { ?>
<?php } ?>
<!-- END POST CONTENT -->
<!-- BEGIN POST TAGS -->
<?php if($meta == "true" && $meta_tags == "true") { ?>
<?php the_tags('<div class="meta-tags"><span>'.__('Tags', 'gp_lang').':</span>', '', '</div>'); ?>
<?php } ?>
<!-- END POST TAGS -->
</div>
<!-- BEGIN POST TEXT -->
</div>
<!-- BEGIN POST -->
<?php if($cols > 1 && $counter %$cols == 0) { ?><div class="clear"></div><?php } ?>
<?php endwhile; ?>
<?php if($pagination == "true") { ?>
<?php gp_pagination($featured_query->max_num_pages); ?>
<div class="clear"></div>
<?php } ?>
</div>
<!-- END POST WRAPPER -->
<?php
$output_string = ob_get_contents();
ob_end_clean();
wp_reset_query();
return $output_string;
}
add_shortcode("posts", "gp_posts");
?>
非常感谢帮助!
答案 0 :(得分:0)
大约1/3的下降你应该看到......
'post_type' => 'post',
将其更改为'post_type' => 'football',
但是,该代码使用了许多参数并执行了许多可能不适用于您的帖子类型的工作,甚至可能与它或您想要的功能冲突。这是很多要扫描的代码,只是看着它我无法判断一个更改是否足够,但是这个更改会使查询从您的football
帖子类型中拉出来。