mehrshad.aryanfar
Registered User
- تاریخ عضویت
- 11 می 2020
- نوشتهها
- 402
- لایکها
- 1,080
- سن
- 44
فکر کنم تستش نکردی، امروز خودم تست کردم، یه مشکلی توی کد بود.
این کد رو لوکال تست کردم اوکی هست:
PHP:<?php $postTags = wp_get_post_terms( get_queried_object_id(), 'post_tag', ['fields' => 'ids'] ); $relatedPostsArgs = [ 'post__not_in' => array( get_queried_object_id() ), 'posts_per_page' => 1, 'orderby' => 'rand', 'tax_query' => [ [ 'taxonomy' => 'post_tag', 'terms' => $postTags ] ] ]; $relatedPosts = query_posts( $relatedPostsArgs ); foreach($relatedPosts as $relatedPost): ?> <div id="temporary-suggestion" class="temporary-suggestion" style="display: block"> <span class="close-suggestion" onclick="function closeSuggestion(){document.getElementById('temporary-suggestion').remove()}closeSuggestion();">X</span> <a target="_blank" href="<?php echo get_permalink($relatedPost->ID) ?>"><img class="temporary-suggestion-image" alt="<?php echo $relatedPost->post_title ?>" src="<?php echo get_the_post_thumbnail_url($relatedPost->ID, "thumbnail") ?>"> <h4 id="temporary-suggestion-title"><?php echo $relatedPost->post_title ?></h4> </a> </div> <style> .temporary-suggestion { position:fixed; top:80px; width:290px; left:3px; z-index:10000; background:#fff; color:#000; border-radius:6px; box-shadow:0 0 17px -2px #000; display:none } .temporary-suggestion a { padding:10px 7px 8px 5px; float:right; color:#020002; font-size:15px; font-weight:700; background-image:none; text-align:center; line-height:24px } .temporary-suggestion h4 { margin:0 } .temporary-suggestion img { height:180px; border-radius:10px } .close-suggestion { width: 37px; height: 37px; position: absolute; top: -20px; right: -10px; background: #ff5700; border-radius: 50%; background-size: 11px; cursor: pointer; border: solid 5px #ea3b64; color: #fff; text-align: center; line-height: 30px; } </style> <?php endforeach; ?>
این قسمت از کد، داره پست های مرتبط با تگ رو تعیین می کنه:
PHP:'tax_query' => [ [ 'taxonomy' => 'post_tag', 'terms' => $postTags ] ]
اگه پست های مرتبط با دسته بندی خاصی رو می خوای باید این قسمت رو تغییر بدی، توی این مطلب آموزش کوئری مطالب وردپرس هست، می خوای بیشتر کد رو ویرایش کنی بد نیست:
WordPress Query Posts by Category, Tag, Custom attribute, and more!
Learn how to List Posts in WordPress using Category name, Tag name, Custom attributes, Post type, Publish date, Random posts, etc. For post listing in WordPress, we use get_posts function to retrieve any WordPress post with desired attributes.mehdinazari.com
مدیریت محتوای ما جوملا هست این کد رو تست کردم متاسفانه جواب نداد . در واقع هر چی گشتم فایل single.php ندیدم ولی خوب روی کدهای خود قالب و بقیه جاها که تست کردم جواب نداد . جوملا 1.5