Yes, mostly, except for the past that says to sort by the sortcode value. If the links are randomly chosen, they will be not be displayed based on their sortcode value.
It loses something without that capability.
You have to be an amateur radio operator to understand why it’s so important.
I will see if I can figure out how to do that table.
Well, I pulled it off. Take a look!: https://www.wb4aej.com/test/
I will be putting that short code on my main page shortly.
The only issue is that it always uses the first fifteen links.
How do I make it select them randomly?
As I said, if you make it take random links, they will also be ordered randomly.
I understood that perfectly.
But it is not displaying random links.
It is displaying the first fifteen every time (not dynamic content).
Right. If you leave the order method to anything other than random, then it will always take the first X items based on the sort method selected. If you want dynamic content, you need to set the sort method to random, which will mean that the random items will not be ordered.
I will see what else I could do, but I can’t promise anything.
Sorry, I didn’t see that Random option.
It’s looking good now!
So… do you need me to do anything on this or is this resolved?
For the sake of discussion, let me explain the sort method I use.
Amateur radio calls consist of a prefix (1 or 2 letters or one letter and a numeral; the prefix identifies the nation in which the station is licensed), the call district (1 numeral) of the nation the station resides in, and the suffix (1 to 3 letters) that uniquely identifies the station.
In an annual publication known as Callbook, the call signs were listed in this order: First by call district, then by suffix, then by prefix.
When I created the Ham Domain database, I wrote a script to sort them in this order.
First, I did it with CGI. Later, I did it with PHP.
I could only accomplish it using a hidden value which I called the ‘sortcode’. It was never displayed. But it was instrumental in getting it in the right order.
When an Amateur Radio Operator looks up a call, it is easiest if they are listed in this order.
I am not a great programmer. But I can usually accomplish it if I give it the amount of time needed. That may be a good deal of time.
I wrote a blurb explaining the dynamics of my sorting method. It was on my old Web site (before WordPress).
I just republished it on the same URL as before. You can now read it at: https://www.wb4aej.com/hamsort .
Thanks for the link, but I am not sure if what you have now works you for or if you’d still need to be able to get 15 random links and be able to sort them by custom text field #1? Or if what’s in place now is ok for you.
It works, no problem.
I would still like to sort them in this way if it is at all possible.
But it works.
As discussed via e-mail, I have added two new fields at the bottom of the Library Configurations Advanced tab to allow users to set a custom WP Query argument and value for that argument. Once set, the following code in your theme’s functions.php file will sort the randomly selected items:
// Filter to sort the random posts displayed
add_filter( 'the_posts', function ( $posts, $q )
{
// First we need remove our filter
remove_filter( current_filter(), __FUNCTION__ );
// Check if our custom parameter is set and is true, if not, bail early
if ( empty( $q->get( 'randomlinknamesort' ) ) ) {
return $posts;
}
$top_10_items = array_splice( $posts, 0, intval( $q->get( 'randomlinknamesort' ) ) );
foreach ( $top_10_items as $key => $item ) {
$top_10_items[$key]->link_custom_text = get_post_meta( $item->ID, 'link_custom_text_1', true );
}
usort( $top_10_items, function ( $item1, $item2 ) {
return $item1->link_custom_text <=> $item2->link_custom_text;
});
// Make sure we have a value for $major_array, if not, bail
if ( empty( $top_10_items ) ) {
return $posts;
}
return array_values( $top_10_items );
}, 10, 2 );
Ok. I will have to remember to put that in the PHP file if I rebuild the site or if I change the theme.
I have copied those lines into my iPad so I will have them if/when I need them.
Thanks, Yannick.
Regards,
Fred
Yannick,
I am trying to find that ‘functions.php’ file in link-library.
I checked every subdirectory but didn’t find it.
I want to upgrade to the latest version of Link Library. But I don’t want to lose the sort routine when I do (I believe you said I would have to insert it each time the plugin was updated).
Regards,
Fred