Organize information in alphabetical order - Html/Javascript or Wordpress

Asked

Viewed 1,992 times

0

Following,

I have a website on wordpress, I created a page inside that site and on that page I will have a list of companies more or less like this:

Company A - (Company name)

  • Company data (This data will be hidden, will appear when the user clicks on the company name).

Company B

Company C

I’ll feed this list manually, then may day I’ll add company that starts with X the next day company that starts with B and so on.

It is possible to make an automatic organization via javascript, where I put one company below the other independent of the initial letter of her name and when it goes to air go alphabetically?

I do not know if it was very clear the doubt, but in short I want to know how to organize a list automatically in alphabetical order.

Thank you.


Guys, how I’m wearing wordpress I chose to use custom post type as colleagues suggested in the answers, legal created the post type is working right, but it is still a bit complicated to organize them in alphabetical order, was reading Codex what is a bit too complicated alias FOR ME, and la says that the query function is in the query.php file, but in my theme does not have this file. I took a look at the functions.php files and also found nothing query, which exact file should "stir"?

  • if each company is a post, you just order the loop, no?

  • It will not be a post each company, they will all be on the same page, I will only hide the details of each one that will only appear if the user clicks on it... But the list of companies will all be on the same page at the bottom of the same one in the example of the post.

  • Yes, but why not make each company a post, or a custom post? It facilitates (and greatly) your life. Ordering posts the wp does alone, no need to reinvent the wheel.

  • I understand, it would really help me a lot, I will have to read about custom post so to try to do, have any example or reference I can take a look at? Thank you. @Caiofelipepereira

  • https://codex.wordpress.org/Post_Types Codex always saving lives. I also gave that answer since maybe I can give you some light. Read about the Wp_query also

  • @Caiofelipepereira ok vlw thanks.

  • @Caiofelipepereira sorry to bother you again, I edited the question if you can take a look. vlw thanks

Show 3 more comments

2 answers

1

Since you are using Wordpress, could not insert these companies as a custom post type? Then just insert a loop on the page to display the companies with the argument of alphabetical order.

My answer will remain incomplete, but for you to base, the code to create a custom post type company would look like this:

add_action( 'widgets_init', 'thinkup_widgets_init' );
register_post_type('empresas', array(
'labels' => array(
            'name' => __( 'empresas' ),
            'singular_name' => __( 'Ver empresas' ),
            'add_new' => __('Novo empresas'),
            'add_new_item' => __('Adicionar novo empresas'),
            'edit_item' => __('Editar empresas'),
            'new_item' => __('Novo empresas'),
            'view_item' => __('Visualizar empresas'),
            'search_items' => __('Pesquisar empresas')
),
'menu_position' => 3,
'public' => true,
'publicly_queryable' => true,
'query_var' => true,
'has_archive' => true,
'hierarchical' => false,
'rewrite' => array('slug' => 'empresas'),
'show_ui' => true,
'capability_type' => 'post',
'supports' => array('title', 'thumbnail', 'revisions' , 'editor', 'excerpt'  )
)
);

A new type of Post will appear in your dashboard, add the companies there. And to pull in a loop these companies, part of the argument code for alphabetical order (orderby) would look something like this:

$args = array(

  'post_type' => array('empresas'),
  'posts_per_page' => 6,
   'orderby' => 'name',
   );

I hope you have an idea about what to do.

  • It would be a good and easier, but I have no idea how to do it... It is possible through a form I insert these links inside the page?

  • Po helped yes, I’m seeing some videos here about , should this code be inserted into functions.php? I’m snooping here to get better how it works and as questions post arise here in stack ... vlw thanks.

  • Yes, the first code goes in functions.php that has the function of creating this new type of Post in your dashboard, to be able to insert the companies there. The second code would be for you to display the companies on the page you want, but missing part of the code, search on google for "loop custom post type".

  • Blz I’ll create here and see what I can vlwww

  • Just one question, creating the post type I can print every "item" I register inside my page? and through the loop I sort the items inside the page is that? correct?

  • @Erick this answer is on the right track, but I suggest you read a little about how WP works

  • @Caiofelipepereira blzz to trying, I made the post type already I can register, now I go to the next step that and try to display in the created page! = D vlw

  • anything, edits your question and we try to answer the problem

Show 3 more comments

-2

This is a sort form for javascript array.

var items = [
  { name: 'Edward', value: 21 },
  { name: 'Sharpe', value: 37 },
  { name: 'And', value: 45 },
  { name: 'The', value: -12 },
  { name: 'Magnetic' },
  { name: 'Zeros', value: 37 }
];
items.sort(function (a, b) {
  if (a.name > b.name) {
    return 1;
  }
  if (a.name < b.name) {
    return -1;
  }
  // a must be equal to b
  return 0;
});

  • 1

    If you will use the code of others to give an example try to search better and put the reference. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort Besides, this script does not answer the question..

Browser other questions tagged

You are not signed in. Login or sign up in order to post.