Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 315 Vote(s) - 3.67 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to create permalink with monthname instead of using monthnum?

#1
I want to redirect my blog articles like this,

[To see links please register here]


But in wordpress it only allows me to use month number,

[To see links please register here]

.

I'm searching for this but not found anything useful. Some unanswered posts and they are not even saying, whether It is possible or not. Even in the wordpress documents there is no reference for this. I found the following code but it changes the url but not linking the post page.

<?php
/**
* Plugin Name: Month Name
* Description: Enables the <code>%monthcode%</code> and <code>%monthname%</code> tag for Permalinks.
* Author: Roger Chen
* License: GPLv2
*/

/**
* Enables use of monthname (january, june) and monthcode (jan, jun).
* Supports permalinks in the form of /2016-nov/61742/..slug.. or /2016-november/61742/..slug..
*/
class MonthName {

/**
* Month Names
*/
public static $monthnames = array(
'january',
'february',
'march',
'april',
'may',
'june',
'july',
'august',
'september',
'october',
'november',
'december',
);

/**
* Month Codes
*/
public static $monthcodes = array(
'jan',
'feb',
'mar',
'apr',
'may',
'jun',
'jul',
'aug',
'sep',
'oct',
'nov',
'dec',
);

/**
* Registers all required hooks
*/
public static function init() {
add_rewrite_tag( '%monthname%', '(' . implode('|', self::$monthnames) . ')' );
add_rewrite_tag( '%monthcode%', '(' . implode('|', self::$monthcodes) . ')' );
add_rewrite_rule(
'^([0-9]{4})-(' . implode( '|', self::$monthnames ) . ')/([0-9]+)/?',
'index.php?p=$matches[3]',
'top'
);
add_rewrite_rule(
'^([0-9]{4})-(' . implode( '|', self::$monthcodes ) . ')/([0-9]+)/?',
'index.php?p=$matches[3]',
'top'
);
}
/**
* Filters the month name and month code tags
*/
public static function filter_post_link( $permalink, $post ) {
if ( false === strpos( $permalink, '%monthname%' ) && false === strpos( $permalink, '%monthcode%' ) ) {
return $permalink;
}

try {
$monthindex = intval(get_post_time( 'n', "GMT" == false, $post->ID ));

$monthname = self::$monthnames[$monthindex - 1];
$monthcode = self::$monthcodes[$monthindex - 1];

$permalink = str_replace( '%monthname%', $monthname, $permalink );
$permalink = str_replace( '%monthcode%', $monthcode, $permalink );

return $permalink;
} catch (Exception $e) {
return $permalink;
}
}

}

add_action( 'init', array( 'MonthName', 'init' ) );
add_filter( 'post_link', array( 'MonthName', 'filter_post_link' ), 10, 2 );



Somebody please say whether it is possible or not. If possible means, can you please say a way to sort out this issue.
Reply

#2
Ok, here's the code. It currently support permalinks of the following format `/2014/nov/23/post-name` or `/2014/november/23/post-name`


<?php
/**
* Plugin Name: Month Name Permalink
* Description: Enables use of <code>%monthcode%</code> or <code>%monthname%</code> tags in permalinks to generate a structure like <code>/2014/nov/23/post-name</code> or <code>/2014/november/23/post-name</code>
* Author: Anand Shah
* License: GPLv2
*/

/**
* Based on the original code by Roger Chen ()
* Plugin enables use of monthname (january, june) and monthcode (jan, jun) in permalinks
* Supports permalinks in the form of /2014/nov/23/post-name or /2014/november/23/post-name
*/

class Month_Name_Permalink {

/**
* Month Names
*/
public static $monthnames = array(
'january',
'february',
'march',
'april',
'may',
'june',
'july',
'august',
'september',
'october',
'november',
'december',
);

/**
* Month Codes
*/
public static $monthcodes = array(
'jan',
'feb',
'mar',
'apr',
'may',
'jun',
'jul',
'aug',
'sep',
'oct',
'nov',
'dec',
);

/**
* Registers all required hooks
*/
public static function init() {
add_rewrite_tag( '%monthname%', '(' . implode('|', self::$monthnames) . ')' );
add_rewrite_tag( '%monthcode%', '(' . implode('|', self::$monthcodes) . ')' );
add_rewrite_rule(
'^([0-9]{4})/(' . implode( '|', self::$monthnames ) . ')/([0-9]{1,2})/(.*)?',
'index.php?name=$matches[4]',
'top'
);
add_rewrite_rule(
'^([0-9]{4})/(' . implode( '|', self::$monthcodes ) . ')/([0-9]{1,2})/(.*)?',
'index.php?name=$matches[4]',
'top'
);

}
/**
* Filters the month name and month code tags
*/
public static function filter_post_link( $permalink, $post ) {
if ( false === strpos( $permalink, '%monthname%' ) && false === strpos( $permalink, '%monthcode%' ) ) {
return $permalink;
}

try {
$monthindex = intval(get_post_time( 'n', "GMT" == false, $post->ID ));

$monthname = self::$monthnames[$monthindex - 1];
$monthcode = self::$monthcodes[$monthindex - 1];

$permalink = str_replace( '%monthname%', $monthname, $permalink );
$permalink = str_replace( '%monthcode%', $monthcode, $permalink );

return $permalink;
} catch (Exception $e) {
return $permalink;
}
}

}

add_action( 'init', array( 'Month_Name_Permalink', 'init' ) );
add_filter( 'post_link', array( 'Month_Name_Permalink', 'filter_post_link' ), 10, 2 );

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through