Highlighting an id anchor result?
-
I’ve got a massive list of books (actually wordpress posts) in text ordered list format.
https://www.tradereadingorder.com/dc-list/
I’ve figured out how to get it to display right, generate in the right order, and have the right id numbers. The intention is to be able to direct people to a specific book by sending them a link with that book value:
https://www.tradereadingorder.com/dc-list/#book-426
edit: replaced the post id based links with <?php echo $post->post_name;?>/slug based links – just will be less confusing to users, I think. New link:
https://www.tradereadingorder.com/dc-list/#superman-transformed
Edit: now https://www.tradereadingorder.com/dc-list/#Superman:%20Transformed
should go to superman: transformed. For example.
What I want to do is also highlight that line on the list, and if possible have it show a couple lines down the page instead of right at top. Anyone know how to do this? I found a little script here:
https://www.webdeveloper.com/forum/showthread.php?t=191971
but I couldn’t seem to get it to work. Maybe it’s because I put it right into middle of the template instead of the header?
edit: in case you’re wondering, I link to it like this:
<?php if ( in_category(1) ){ echo ‘
post_name; echo ‘”>View in place on the DC Reading Order‘; } ?>Seems to be working so far, though I wish I knew how to do that selective styling. still no luck.
edit: oh damnit! I put it into a “sidebar” widgetized space so I could selectively cache that huge list and save my server a lot of trouble. But then the slug ids stopped generating. Everything else works.. I don’t get it!
edit again: ok, I got around it kind of by using the_title();. I don’t really like this, because two books might have been published with the same title, but I use the slug to differentiate the entries. Plus links with spaces and punctuation can be wonky. The mixups will be rare, but they could still happen. Anyway, guess it works for now.
Still hoping for a solution to the original issue though haha
- The topic ‘Highlighting an id anchor result?’ is closed to new replies.