like above, I want build it for my theme
As far as I understand your requirement, you want to show a “table of content” above your each post.
The concept is, loop through your post content and get all the headings. Generate a ordered or un-ordered list of those headings and inject that above the content.
There is a good article on css-tricks you can check that. https://css-tricks.com/automatic-table-of-contents/
Thank you very much !