رفتن به مطلب

نمایش مطالب مرتبط برای پست سفارشی


پست های پیشنهاد شده

سلام دوستان

یه کد میخوام مطالب مرتبط را نشون بده ولی برای پست سفارشی

برچسب ها را به این صورت ایجاد کردم taxonomy-work_tag

و پستهای برچسب دار هم در سایت دارم

این کد را هم استفاده کردم ولی چیزی نمایش داده نمیشه


<?php
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$args=array(
'tag__in' => $tag_ids,
'post__not_in' => array($post->ID),
'showposts'=>5,
'caller_get_posts'=>1
);
$my_query = new wp_query($args);
if( $my_query->have_posts() ) {
echo '<ul>';
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="پیوند دائمی به <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
<?php
}
echo '</ul>';
}
}
wp_reset_query();
?>

لینک به ارسال

شما بعد ایجاد پست سفارشی، برچسب ها رو براش تعریف کردید؟

لینک به ارسال

شما بعد ایجاد پست سفارشی، برچسب ها رو براش تعریف کردید؟

بله تعریف کردم و طبق این آموزش http://forum.wp-parsi.com/tutorials/article/10-%D9%BE%D8%B3%D8%AA-%D8%B3%D9%81%D8%A7%D8%B1%D8%B4%DB%8C-%D8%B4%DB%8C%D9%88%D9%87-%D9%86%D9%85%D8%A7%DB%8C%D8%B4-%D8%B9%D9%86%D8%A7%D9%88%DB%8C%D9%86-%D8%AF%D8%B3%D8%AA%D9%87-%D9%87%D8%A7-%D9%88-%D8%A8%D8%B1%DA%86%D8%B3%D8%A8-%D9%87%D8%A7/

با این کد


<?php echo get_the_term_list( $post->ID, 'lntag', '<br />برچسب ها: ', ', ', '' ); ?>

فراخوانی کردم و الان برچسبها در صفحات نمایش داده میشه

ولی مطالب مرتبط نمایش داده نمیشه

لینک به ارسال

به $args خاصیت زیر رو هم اضافه کنید:

'post_type' => 'your post type here',

این رو هم تست کنید:

<?php

add_shortcode('common_content','malama_get_common_content');

function malama_get_common_content($atts){

extract( shortcode_atts( array(

'tax'=>'category',

'posts_per_page'=>4,

'orderby'=>'name',

'order'=>'ASC',

'hide_empty'=>false,

'description'=>true,

'show_link'=>true,

'show_title'=>true,

'show_thumbnail'=>true,

'thumbnail_size'=>'thumbnail',

'show_description'=>true,

'post_type'=>array('page','post'),

'list_id'=>'content-list'

), $atts ) );

$out=null;

$terms = array();

//uses the current post/page/custom post type that's in the loop

global $post;

//convert post_type to an array for our query use below if it's not the default

//this allows us to accept the shortcode argument as a comma-separated list

if(!is_array($post_type)){

$post_type = explode(",",$post_type);

}

//get the terms of the current post for the requested taxonomy

$termlist = get_the_terms($post->ID,$tax);

if($termlist && !is_wp_error($termlist)){

foreach($termlist as $term){

$terms[]=$term->slug;

}

}

//get the list of matching posts/pages/custom post type

$args = array(

'post_type'=>$post_type,

'posts_per_page'=>$posts_per_page,

'tax_query'=>array(

array(

'taxonomy'=>$tax,

'field'=>'slug',

'terms'=>$terms

)

)

);

$content = get_posts($args);

if($content && !is_wp_error($content)){

$out.="<ul id="'.$list_id.'">\n";

foreach($content as $item){

$out.="<li>";

$linkstart = null;

$linkend = null;

if($show_link===true || $show_link==="true"){

$linkstart = '<a title="'.$item->post_title.'" href="'.get_permalink($item->ID).'">';

$linkend = '</a>';

}

if($show_thumbnail===true || $show_thumbnail==="true"){

if(has_post_thumbnail($item->ID)){

$out.= $linkstart.get_the_post_thumbnail($item->ID,$thumbnail_size).$linkend;

}else{

$out.="<div class='image-blank'>No Image</div>";

}

}

if($show_title===true || $show_title==="true" || $show_description===true || $show_description==="true"){

$out.='<div class="item-text">'

if($show_title===true || $show_title==="true"){

$out.='<h3>'.$linkstart.$item->post_title.$linkend.'</h3>';

}

if($show_description===true || $show_description==="true"){

$out.="<div class='description'>".apply_filters('the_content',$item->post_content)."</div>\n";

}

$out.="</div>\n";

}

$out.="</li>\n";

}

$out.="</ul>\n";

}

return $out;

}

?>

لینک به ارسال

به $args خاصیت زیر رو هم اضافه کنید:

'post_type' => 'your post type here',

این رو هم تست کنید:

روش اول که جواب نداد

روش دوم هم این ارور داد Parse error: syntax error, unexpected ';' تو خط مورد نظر هم این کد قرار داره

لاین 48


if($content && !is_wp_error($content)){

لینک به ارسال

بشه این:

if($content && !is_wp_error($content)){

به این صورت هم تست کردم ارور داد تو این خط


if($termlist && !is_wp_error($termlist)){

واین هم به این صورت تغییر دادم


if($termlist &&; !is_wp_error($termlist)){

دوباره این ارور داد Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING

تو خط 49 یعنی این خط


$out.="<ul id="'.$list_id.'">\n";

لینک به ارسال

بشه این:

$out.="<ul id='$list_id'>\n";

& ها رو به & تبدیل کنید

مثل اینکه یک دیباگ اساسی میخواست :)

لینک به ارسال

بشه این:

$out.="<ul id='$list_id'>\n";

& ها رو به & تبدیل کنید

مثل اینکه یک دیباگ اساسی میخواست :)

تمام مراحل انجام شد. این ارور Parse error: syntax error, unexpected T_IF

تو این خط


if($show_title===true || $show_title==="true"){

حالا این همه زحمت میدیم به شما خدا کنه به نتیجه برسیم :)

لینک به ارسال

اینطور تست کنید:

if(($show_title===true) || ($show_title=="true")){

نشد باز همون ارور Parse error: syntax error, unexpected T_IF

از این کد


if(($show_title===true) || ($show_title=="true")){

لینک به ارسال

نشد با یک کد دیگه باید تست کنیم:

if( $show_title = true || $show_title == "true" ){

لینک به ارسال
نشد با یک کد دیگه باید تست کنیم:
if( $show_title = true || $show_title == "true" ){

نشد متاسفانه اگر کد دیگه ای لطف کنین ممنون میشم

البته این کد را در تو این سایت پیدا کردم نمیدونم جواب میده یا نه


<?php
// Generate an array of taxonomy IDs
$tax_IDs = array();
foreach ($tags as $tag) {
$tax_IDs[] = $tag->ID;
}
// Use your array of taxonomy IDs in the query args
$args = array(
'post_type' => 'your_custom_post_type',
'post__not_in' => array($post->ID),
'showposts'=> 3,
'tax_query' => array(
array(
'taxonomy' => 'your_custom_taxonomy',
'field' => 'id',
'terms' => $tax_IDs
)
)
);
// Run your query
$my_query = new WP_Query($args);
?>

این ارورو Warning: Invalid argument supplied for foreach() in

تو این خط فعلا داده


foreach ($tags as $tag) {

لینک به ارسال

این رو به بالاش اضافه کنید:

$taxonomy = 'services';//  e.g. post_tag, category, custom taxonomy
$tax_args=array('orderby' => 'none');
$tags = wp_get_post_terms( $post->ID , $taxonomy, $tax_args);

لینک به ارسال

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع ...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

×
×
  • اضافه کردن...