চমত্কার ইউআরএল থেকে ডিফল্ট পারমলিংক কাঠামো পান


15

যখন কোনও একক পোস্টে কোনও বিভাগের পৃষ্ঠা থেকে বা সেটির জন্য যে কোনও পৃষ্ঠা ক্লিক করা হয়, আপনি সেই রেফারারের ইউআরএল পেতে এবং ক্যোয়ারীর স্ট্রিংটি পেতে এটি পার্স করতে পারেন। তবে এটি কেবলমাত্র ডিফল্ট পারমালিঙ্ক কাঠামোর সাথে কাজ করে

উদাহরণস্বরূপ যখন রেফারার একটি বিভাগ পৃষ্ঠা:

var_dump( parse_url( wp_get_referer() ) );ডিফল্ট পারমালিঙ্ক কাঠামো সহ নিম্নলিখিত আউটপুট দেয়

array(4) {
  ["scheme"]=>
  string(4) "http"
  ["host"]=>
  string(9) "localhost"
  ["path"]=>
  string(11) "/wordpress/"
  ["query"]=>
  string(5) "cat=7"
}

var_dump()পারমালিঙ্কস সেট করা একই সাথে /%postname%/, আপনি যা পান তা এটি

array(3) {
  ["scheme"]=>
  string(4) "http"
  ["host"]=>
  string(9) "localhost"
  ["path"]=>
  string(32) "/wordpress/category/uit-my-lewe/"
}

আমি pathকোডের দ্বিতীয় ব্লকটি দিয়ে এইটি ব্যবহার করতে পারি get_category_by_path(), আমি বিভাগের জিনিসগুলি পেতে পারি

আমার সমস্যাটি হ'ল, আমি কীভাবে কর সংক্রান্ত শর্তে এটি ব্যবহার করব about

আমি একটি পরীক্ষা করেছি। আমার একটা কাস্টম ট্যাক্সনমি আছে event_cat। যদি আমি এটিতে আবারও লিখি event-slug, আমি পারমালিঙ্ক কাঠামো হিসাবে নিম্নলিখিতটি pathব্যবহার করি/%postname%/

/wordpress/event-slug/5-star/

এবং

event_cat=5-star

ডিফল্ট কাঠামো ব্যবহার করে

স্বয়ংক্রিয়ভাবে আমার বিভাগের নামটি ইউআরএলে থাকবে না, কেবল আমার পদটির স্লাগ। সুতরাং, এই শব্দটি থেকে পদার্থ প্রাপ্তিতে খুব ব্যর্থ নিরাপদ পদ্ধতি হবে না।

আমার প্রশ্নটি হল, আমি কীভাবে সঠিকভাবে ডিফল্ট পারমলিংক কাঠামোটি কোয়েরি স্ট্রিং, বা কোয়েরি স্ট্রিং বা পারমালিঙ্ক /%postname%/কাঠামো থেকে ট্যাক্সোনমি এবং পদ নামটি পেতে পারি?


এটি আপনার এখন কারও কাছে url থেকে ক্যোয়ারী লাইব্রেরির মতো শোনাচ্ছে । ;)
প্রথম

তুমি কেন এটা করছ? (এক্সওয়াই সমস্যা)
টম জে নওয়েল

ধন্যবাদ @ রার্স্টকে জানা উচিত ছিল যে কারওর কাছে এইরকম কিছু থাকবে :-)। বিলে এটি ফিট হবে
পিটার গুজন

আমি এখনও জিএম এর উত্তর দেখতে চাই এটি কীভাবে কাজ করে তা ব্যাখ্যা করে।
প্রথম

@ টমজেউওয়েল মূলত আমার জানা দরকার যে কোনও পোস্টকে একটি কর শুল্ক পৃষ্ঠা থেকে উল্লেখ করা হয়েছিল, যদি তা হয় তবে আমার কোন শব্দটি জানা উচিত। পরবর্তী / পূর্ববর্তী পোস্ট হিসাবে কোন পোস্টটি পরিবেশন করতে হবে তা গণনা করতে হবে। পোস্টগুলি একাধিক পদ থাকলেও এটি কেবল তখনই প্রয়োজনীয়। বোর্ড জুড়ে একক শর্তাবলী সহজ
পিটার গোসেন

উত্তর:


10

সবার আগে আমাকে বলতে হবে যে wp_get_referer()এটি 100% নির্ভরযোগ্য নয় কারণ এটি পিএইচপিএন ডক্স $_SERVER['HTTP_REFERER']থেকে 100% নির্ভরযোগ্য নয় :

পৃষ্ঠার ঠিকানা (যদি থাকে) যা ব্যবহারকারী এজেন্টকে বর্তমান পৃষ্ঠায় উল্লেখ করেছে। এটি ব্যবহারকারী এজেন্ট দ্বারা সেট করা হয়েছে। সমস্ত ব্যবহারকারীর এজেন্ট এটি সেট করবে না এবং কিছু HTTP_REFERER কে বৈশিষ্ট্য হিসাবে সংশোধন করার ক্ষমতা সরবরাহ করে। সংক্ষেপে, এটি সত্যিই বিশ্বাস করা যায় না।

বিকল্প সমাধান

আপনি যদি ইউআরএল পোস্টে যুক্ত করতে পারেন তবে এমন কোয়েরি যুক্তি যা পোস্টটি এসেছে কোথা থেকে আসে, এটি আরও নির্ভরযোগ্য হবে এবং আপনার প্রয়োজন হবে না পার্স একটি টার্ম অবজেক্ট পেতে আপনাকে ইউআরএল ।

উদাহরণ:

add_filter('post_link', function($permalink) {
  if (is_category() && ($cat = get_queried_object())) {
    $permalink = esc_url(add_query_arg(array('catfrom' => $cat->term_id), $permalink));
  }
  return $permalink;
});

এটি করার মাধ্যমে, বিভাগের পৃষ্ঠা থেকে ক্লিক করা পোস্ট পার্মালিঙ্কগুলি আপনাকে কোনও ইউআরএলটিতে প্রেরণ করবে

http://example.com/wordpress/post-name?catfrom=12

এবং নির্ভর করেই ব্যবহারকারী কোথা থেকে আসে তা আপনি সহজেই বুঝতে পারবেন $_SERVER['HTTP_REFERER'] এবং অন্য কোনও প্রচেষ্টা ছাড়াই ।

আপনার প্রশ্নের উত্তর দিতে

কোনও url থেকে শুরু হওয়া ক্যোয়ারী তথ্য পান এমন কিছু যা ওয়ার্ডপ্রেস WP::parse_request()পদ্ধতির অভ্যন্তরে করে ।

এই পদ্ধতিটি কেবল একবার এবং কেবলমাত্র "প্রধান" ইউআরএল (কোনও ইউআরএল ব্যবহারকারী দেখছেন) এর জন্য ব্যবহৃত হবে এবং স্বেচ্ছাচারিত ইউআরএলগুলির জন্য নয়।

কয়েক মাস আগে আমি url থেকে ক্যোয়ারী লিখেছি সালিসী ইউআরএলগুলির জন্য একই জিনিস করার লক্ষ্য নিয়ে url প্লাগইন ।

আমি যা করেছি তা হ'ল WP::parse_request()এটিকে আরও বুদ্ধিমান ওওপি কোডে রিফ্যাক্টর করা এবং এটি নির্বিচারে ইউআরএলগুলি দিয়ে কাজ করা (উদাহরণস্বরূপ ইউআরএল থেকে প্রক্রিয়াটি গ্রহণের পরিবর্তে আর্গুমেন্ট হিসাবে গ্রহণ করা হয়েছে)$_SERVER প্রসারণের ভার )।

আমার প্লাগিন ব্যবহার করে আপনি পারেন

$args = url_to_query('/wordpress/event-slug/5-star/');

var_dump($args); // array( 'event_slug' => '5-star' );

সুতরাং আপনি new WP_Queryএকটি ইউআরএল থেকে শুরু করে ক্যোয়ার আর্গুমেন্টগুলি (এমন কোনও কিছু যা আপনি সরাসরি যেতে পারেন ) পান, ঠিক এটিWP::parse_request() ঘটে।

আপনার ক্ষেত্রে আপনি সম্ভবত একটি কোয়েরি চালানোর প্রয়োজন ছাড়াই আরোগুলি অ্যারেটি পরীক্ষা করতে পারেন।

এটি অবশ্যই কাজ করতে পারে তবে আমি মনে করি যে ইউআরএলকে বিশ্লেষণ করার জন্য অতিরিক্ত প্রচেষ্টা করা এবং এর অবিশ্বাস্যতা $_SERVER['HTTP_REFERER']আপনার স্কোপগুলির জন্য প্রথম সমাধানটিকে আরও ভাল করে তোলে।


যদি আমি পোস্টের আইডি পেতে চাই বা রেফারারের কাছ থেকে স্লাগ করতে পারি .. আমি কীভাবে এটি পেতে পারি .. যেমন কোয়েরি অবজেক্টে সেই তথ্য নেই ...
পার্থ কুমার

5

এই প্রশ্নের মূল উদ্দেশ্যটি ছিল একক পোস্টটি কোথা থেকে উল্লেখ করা হয়েছিল তা জানা এবং তারপরে পোস্ট রেফারার অনুসারে পরবর্তী এবং পূর্ববর্তী পোস্টগুলি পরিবেশন করা।

আমি যা অর্জন করতে চেয়েছিলাম তা উদাহরণস্বরূপ:

বিভাগ, বিভাগ, বিভাগ, ট্যাগ, অনুসন্ধান বা লেখক সংরক্ষণাগার পৃষ্ঠা থেকে একটি পোস্ট ক্লিক করা হয়। এই সংরক্ষণাগারগুলি রেফারার হিসাবে কাজ করে। এখন, সাধারণত কেউ আমার প্রশ্নের মতো ব্যবহার করে wp_get_referer()সেই রেফারারটি পেতে এবং এটি আরও প্রশ্নে ব্যবহার করতে পারে। @ জিএম দ্বারা উপরে তার গৃহীত উত্তরে বর্ণিত হিসাবে , এই পদ্ধতিটি নির্ভরযোগ্য নয়, তাই আমি গিয়ে তার বিকল্প সমাধানটি ব্যবহার করেছি

অন্য সমস্যাটির প্রয়োজন ছিল এই রেফারারটি সঞ্চয় করার জন্য এক ধরণের কুকি বা সেশন ব্যবহার করা, যাতে আপনি যখন নির্দিষ্ট সঞ্চিত সংরক্ষণাগারে ক্লিক করা মূল একক পোস্ট থেকে দূরে নেভিগেট করেন তখন আপনি মূল রেফারারের পোস্টগুলি সরিয়ে ফেলতে পারেন। যেহেতু কুকিগুলিও শেষ ব্যবহারকারীর দ্বারা নিয়ন্ত্রিত হয় এবং এটি নির্ভরযোগ্য নয় এবং ওয়ার্ডপ্রেস ডিফল্টরূপে সেশনগুলি ব্যবহার করে না, আমি @ জিএম বিকল্প সমাধান ব্যবহার করে পরবর্তী এবং পূর্ববর্তী পোস্ট লিঙ্কগুলি রিফেক্ট করেছিলাম আমার মূলটি পরীক্ষা করে সংরক্ষণ করার একটি নির্ভরযোগ্য উপায় থাকতে করেছিলাম রেফারার।

এটিই আমি নিয়ে এসেছি এবং আমি আশা করি যে অদূর ভবিষ্যতে কেউ এটির কাজে লাগবে। দয়া করে আপনার প্রয়োজন অনুসারে কোডটি ব্যবহার করুন এবং অপব্যবহার করুন, কেবল একটি অনুরোধ: এই প্রশ্নের পিছনে একটি লিঙ্ক রেখে দিন। :-)

অনুসরণ করতে কোডে নোটস

  • এই কোডটি বেশ দীর্ঘ এবং নিবিড়, সুতরাং আমি বিশদে যাব না। কোড ভাল মন্তব্য করা হয়েছে

  • এই কোডটিতে একই শব্দটির মধ্যে পোস্টগুলির মধ্যে পৃষ্ঠার বিকল্প রয়েছে ঠিক যেমন ওয়ার্ডপ্রেসে ডিফল্ট next_post_link()এবং previous_post_link()ফাংশনগুলির মতো । নেটিভ ফাংশনগুলির মতোই, আপনাকে বিভাগটি নির্ধারণ করতে হবে। জন্য ডিফল্ট মান in_same_termহল trueএবং বর্গীকরণ সূত্র হলcategory

  • সবচেয়ে গুরুত্বপূর্ণ, এই কোডটির জন্য পিএইচপি 5.4+ প্রয়োজন

কোড

<?php
/**
 * @author Pieter Goosen
 * @license GPLv2 
 * @link http://www.gnu.org/licenses/gpl-2.0.html
 *
 * The functions on this page returns the next and previous post links
 * depending on what has been set
 *
 * @return function single_post_navigation()
*/ 

/**
 * Register six new query variables aq, ,cq, tq, ttq, taq, and sq set by 
 * the term_referer_link function
 *
 * @see http://codex.wordpress.org/WordPress_Query_Vars
 *
*/ 
add_filter( 'query_vars', function ( $vars ) {

    $vars[] = 'cq'; // Will hold category ID
    $vars[] = 'tq'; // Will hold taxonomy name
    $vars[] = 'ttq'; // Will hold term slug
    $vars[] = 'sq'; // Will hold search query
    $vars[] = 'aq'; // Will hold author name
    $vars[] = 'taq'; // Will hold tag id


    return $vars;

}, 10, 3 );

/**
 * Conditional tag to check whether or not a query_var has been set
 *
 * @param string $query_var query_var to check
 * @return (bool) true if query_var exists, false on failure
 *
*/
function has_query_var( $query_var ) {

    $array = $GLOBALS['wp_query']->query_vars;

    return array_key_exists( $query_var, $array );

}

/**
 * For posts being clicked from a category page, the query_var, 'cq' is set. 
 * 'cq' holds the category ID
 *
 * Set two query_var, 'tq' and 'ttq' to single posts that was clicked on from 
 * taxonomy pages. 'tq' holds the taxonomy name while 'ttq' holds the term name
 *
 * For search queries, the query_var, 'sq' is set to single posts that was clicked on from 
 * the search page. 'sq' holds the search query value
 *
 * For posts being clicked from an author page, the query_var, 'aq' is set. 
 * 'aq' holds the author ID
 *
 * For posts being clicked from a tag page, the query_var, 'taq' is set. 
 * 'taq' holds the tag ID
 *
 * This function replaces the wp_get_referer() and $_SERVER['HTTP_REFERER']
 * functions that are not very reliable
 * @see php.net manual $_SERVER['HTTP_REFERER']
 * @link http://php.net/manual/en/reserved.variables.server.php
 *
 * @uses add_query_arg()
 * @uses post_link
 * @uses post_type_link
 *
*/
add_filter( 'post_type_link', 'term_referer_link', 10, 3 );
add_filter( 'post_link', 'term_referer_link', 10, 3 );

function term_referer_link( $permalink, $post ) {

    switch ( true ) {

        case ( is_category() ):

            $category = get_queried_object_id();

            $args = [
                'cq'    => $category, 
            ];

            break;
        case ( is_tax() ):

            $term = get_queried_object();

            $args = [
                'tq'    => $term->taxonomy, 
                'ttq'   => $term->slug
            ];

            break;

        case ( is_search() ):

            $search = get_search_query();

            $args = [
                'sq'    => $search, 
            ];

            break;

        case ( is_author() ):

            $author = get_queried_object_id();

            $args = [
                'aq'    => $author,
            ];

            break;

        case ( is_tag() ):

            $tag = get_queried_object_id();

            $args = [
                'taq'   => $tag,
            ];

            break;

    }

    if( isset( $args ) ) { 

        $permalink  = add_query_arg( $args, $permalink );

    }

    return $permalink;

}

/**
 * @access private
 * This function is marked private and should not be used in any other functions
 *
 * This is a helper function for the main navigation function 
 * 
 * This function checks if any of the query variables is set in the single
 * post page URL. If they exist, the values are retrieved that were set
 * by the query variables
 *
 * These query variables are converted into query arguments for the query that will
 * be used to determine the current post position and the posts adjacent to the
 * current post which will translate in the next and previous post. 
 * 
 * When no query variables are present, an empty array of arguments is returned
 * 
 * @uses has_query_var()
 * @return (array) $add_query_args_to_args Query variable to determine the next/previous post links
 * @see http://codex.wordpress.org/Function_Reference/add_query_arg
 *
*/
function _query_vars_to_query_args() {

    switch ( true ) {

        case ( has_query_var( 'cq' ) ): // For category referrer

            $category = get_query_var( 'cq' );

            $add_query_args_to_args = [
                'cat' => $category,
            ];

            break;

        case ( has_query_var( 'tq' ) && has_query_var( 'ttq' ) ): // For taxonomy term referrer

            $taxonomy   = get_query_var( 'tq' );
            $term       = get_query_var( 'ttq' );

            $add_query_args_to_args = [
                'tax_query' => [
                    [
                        'taxonomy'          => $taxonomy,
                        'field'             => 'slug',
                        'terms'             => $term,
                        'include_children'  => false,
                    ],
                ],
            ];

            break;

        case ( has_query_var( 'sq' ) ): // For search referrer

            $search = get_query_var( 'sq' );

            $add_query_args_to_args = [
                's' => $search,
            ];

            break;

        case ( has_query_var( 'aq' ) ): // For author referrer

            $author = get_query_var( 'aq' );

            $add_query_args_to_args = [
                'author' => $author,
            ];

            break;

        case ( has_query_var( 'taq' ) ): // For tag referrer

            $tag = get_query_var( 'taq' );

            $add_query_args_to_args = [
                'tag_id' => $tag,
            ];

            break;

        default: // Default: returns empty array on any other archive or homepage

            $add_query_args_to_args = [];

            break;

    }

    return $add_query_args_to_args;

}
/**
 * @access private
 * This function is marked private and should not be used in any other functions
 *
 * This is a helper function for the main pagination function. This function 
 * checks if the defined query variables has been set in the URL of a single
 * post
 * 
 * If any of the query variables are found on any given single post page, then 
 * these query variables will be set to the next and previous post links according
 * to the single post's query variables
 * 
 * This way, next and previous posts will be shown from the same category, term, 
 * search query or author archive from which the original single post was referred 
 * from. 
 *
 * If a single post was referred from any other archive or main page, these query 
 * variables will not be set, and function will default to an empty array and no
 * query variables will be set to the next and previous post links
 *
 * @uses has_query_var()
 * @return (array) $qv Query variable to add to next/previous post links
 * @see http://codex.wordpress.org/Function_Reference/add_query_arg
 *
 * @todo Other archives can be added later
*/
function _add_query_vars_to_nav_links() {

    switch ( true ) {

        case ( has_query_var( 'cq' ) ): // For category referrer

            $category = get_query_var( 'cq' );

            $qv = [
                'cq'    => $category, 
            ];

            break;

        case ( has_query_var( 'tq' ) && has_query_var( 'ttq' ) ): // For taxonomy term referrer

            $taxonomy   = get_query_var( 'tq' );
            $term       = get_query_var( 'ttq' );

            $qv = [
                'tq'    => $term->taxonomy, 
                'ttq'   => $term->slug
            ];

            break;

        case ( has_query_var( 'sq' ) ): // For search referrer

            $search = get_query_var( 'sq' );

            $qv = [
                'sq'    => $search, 
            ];

            break;

        case ( has_query_var( 'aq' ) ): // For author referrer

            $author = get_query_var( 'aq' );

            $qv = [
                'aq'    => $author,
            ];

            break;

        case ( has_query_var( 'taq' ) ): // For tag referrer

            $tag = get_query_var( 'taq' );

            $qv = [
                'taq'   => $tag,
            ];

            break;


        default: // Default: returns empty array on any other archive or homepage

            $qv = [];

            break;

    }

    return $qv;

}

/**
 * This function returns navigation links to the next/previous single post
 * There are choices to which taxonomy to use, and whether adjacent posts should
 * be of the same term or not
 * 
 * When in_same_term is set to true, you have a choice to use the parent term or
 * child term if a post belongs to both. If the parent term is not available, the child term 
 * is automatically used
 *
 * @param array $defaults An array of key => value arguments. Defaults below 
 * - bool in_same_term       Whether or not next/previous post should be in the same term Default true
 * - bool parent_term        If in_same_term is true, should the parent or child terms be used Default true
 * - string/array taxonomy   The taxonomy from which terms to use Default category
 * - string/array post_types Post types to get posts from. Uses current post's post type on empty string. Default empty string 
 * - string previous_text    Text to display with previous post Default 'Previous post'
 * - string next_text        Text to display with next post Default 'Next post'
 *
 * @return string $links
*/ 
function get_single_post_navigation( $args = [] ) {

    // Sets the default arguments for default usage
    $defaults = [
        'in_same_term'      => true,
        'parent_term'       => true,
        'post_types'         => '',
        'taxonomy'          => 'category',
        'previous_text'     => __( 'Previous post' ),
        'next_text'         => __( 'Next post' ),
    ];

    // Merges the default arguments with user defined variables
    $args = wp_parse_args( $args, $defaults );

    /**
     * Get the currently displayed single post. For this use 
     * get_queried_object() as this is more safe than the global $post
     *
     * The $post global is very easily changed by any poorly written custom query
     * or function, and is there for not reliable
     *
     * @see Post below on WPSE for explanation
     * @link /wordpress//q/167706/31545
    */ 
    $single_post = get_queried_object();

    /**
     * Use the post type of the current post or post types entered in args
     *
    */ 
    $post_type   = ( empty( $args['post_types'] ) ) ? $single_post->post_type : $args['post_types'];


    // Set the variable query variables according to condition
    if( !empty( _query_vars_to_query_args() ) ) {

        $query_args = _query_vars_to_query_args(); 

    }elseif( true === $args['in_same_term'] ) {

        $terms =  wp_get_post_terms( $single_post->ID, $args['taxonomy'] ); 

        if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){

            foreach ( $terms as $term ) {
                if( $term->parent === 0 ) {
                    $parent[] = $term;
                }else{
                    $child[] = $term;
                }
            }   

            $term_id = ( $args['parent_term'] === true && isset( $parent ) ) ? $parent[0]->term_id : $child[0]->term_id;

            $query_args = [ 
                'tax_query' => [
                    [
                        'taxonomy'          => $args['taxonomy'],
                        'field'             => 'term_id',
                        'terms'             => $term_id,
                        'include_children'  => false,
                    ],
                ],
            ];
        }

    }else{

        $query_args = [];

    }

    // Default arguments to use with all the conditional statements above
    $default_query_args = [ 
        'post_type'         => $post_type,
        'fields'            => 'ids',
        'posts_per_page'    => -1,
        'suppress_filters'  => true,
    ];

    // Merges the default arguments with the arguments from the conditional statement
    $combined_args = wp_parse_args( $query_args, $default_query_args );

    $q = new WP_Query( $combined_args );

    // Get the current post position. Will be used to determine adjacent posts
    $current_post_position = array_search( $single_post->ID, $q->posts );

    // Get the returned values from '_add_query_vars_to_nav_links()' to build links
    $get_qv = _add_query_vars_to_nav_links(); 

    // Get the next/older post ID
    if ( array_key_exists( $current_post_position + 1 , $q->posts ) ) {
        $next = $q->posts[$current_post_position + 1];
    }

    // Get post title link to the next post
    if( isset( $next ) ) {

        $next_post      = get_post( $next );
        $next_post_link = ( !empty( $get_qv ) ) ? add_query_arg( $get_qv, get_permalink( $next ) ) : get_permalink( $next );
        $next_title     = '<span class="meta-nav">' . $args['next_text'] . ': </span><a href="' . $next_post_link . '">' . $next_post->post_title . '</a></br>';

    }else{

        $next_title     = '';

    }

    // Get the previous/newer post ID
    if ( array_key_exists( $current_post_position - 1 , $q->posts ) ) {
        $previous = $q->posts[$current_post_position - 1];
    }

    // Get post title link to the previous post
    if( isset( $previous ) ) {

        $previous_post      = get_post( $previous );
        $previous_post_link = ( !empty( $get_qv ) ) ? add_query_arg( $get_qv, get_permalink( $previous ) ) : get_permalink( $previous );
        $previous_title     = '<span class="meta-nav">' . $args['previous_text'] . ': </span><a href="' . $previous_post_link . '">' . $previous_post->post_title . '</a></br>';

    }else{

        $previous_title     = '';

    }

    // Create the next/previous post links
    $links  = '<nav class="navigation post-navigation" role="navigation">';
    $links .= '<div class="nav-links">';
    $links .= $previous_title;
    $links .= $next_title;
    $links .= '</div><!-- .nav-links -->';
    $links .= '</nav><!-- .navigation -->';

    // Returns the post links with HTML mark-up
    return $links;

}

/** 
 * This function is simply just a wrapper for the main navigation
 * function and echo's the returned values from the main navigation
 * function
*/ 
function single_post_navigation( $args = [] ) {

    echo get_single_post_navigation( $args );

}

একক নমুনা ব্যবহার করুন

আপনার যদি একই পদটির মধ্যে পোস্ট নেভিগেট করার প্রয়োজন না হয়, সমস্ত পোস্টের ধরণের পোস্টগুলি পান এবং আপনার লিঙ্কটি সহ পরবর্তী এবং পূর্ববর্তী পাঠ্যটি কাস্টমাইজ করুন, আপনি নিম্নলিখিতটি করতে পারেন:

$args = [
    'in_same_term'     => false,
    'post_types'       => ['post', 'my_post_type'],
    'previous_text'      => __( 'Vorige Pos' ),
    'next_text'      => __( 'Volgende Pos' ),
];

single_post_navigation( $args );

সম্পাদনা 1

এসও-র একটি পোস্টের অনুরোধে এবং এ এর ​​অংশ হিসাবে @todo, আমি এখন কেবলমাত্র বর্তমান পোস্টের পোস্ট টাইপ থেকে পোস্টের মধ্যে নেভিগেট করার জন্য সমর্থন চালু করি নি, তবে ব্যবহারকারী দ্বারা ব্যবহৃত পোস্টের ধরণের অ্যারে থেকে ব্যবহার করেpost_types প্যারামিটার । আপডেট কোড দেখুন।

সম্পাদনা 2

যোগ 'suppress_filters' => true,করার জন্য WP_Queryআর্গুমেন্ট যাতে পত্রাঙ্কন মধ্যে ব্যবহার করে এমন ফিল্টারটি পরিবর্তন করা হয় নাWP_Query

আমাদের সাইট ব্যবহার করে, আপনি স্বীকার করেছেন যে আপনি আমাদের কুকি নীতি এবং গোপনীয়তা নীতিটি পড়েছেন এবং বুঝতে পেরেছেন ।
Licensed under cc by-sa 3.0 with attribution required.