To insert code use <code>...</code>.
link to latest post - How to?
  • Have been looking around for a way to have a button that links to the latest post of a certain category.
  • 9 Comments sorted by
  • I had found that earlier but I don't think it solves my issue. I have on a home page a button that says "Click here to read the latest rant!" and when you click it takes you to the latest post of that category, already open and ready to read.
  • so actually you want the button to execute the php code which presents the latest post in a certain category?

    would it help if you could do this in a widget?

    http://www.wpinsite.com/wp-plugins/how-to-add-and-execute-php-code-on-wordpress-widgets/

    or you have to link the button to page like this simple example...


    http://stackoverflow.com/questions/1697484/a-button-to-start-php-script-how

    http://www.daniweb.com/web-development/php/threads/307632

    in the php file you can put the function which calls the page containing the post you want to display.


    The button needs to trigger a piece of php code which is either already added to the current page (this you can do by changing the home page template (or even page template). Be sure you give it a unique name so the function cannot be triggered by a ordinairy submit button.

    then link the button to that function. So on click the function or script is called which does the job

    hmmm i agree there should be a easier way. Have to think about this again.
  • Thanks for the quick response. No, can't do in widget. I am looking at some options and will post if they work.
  • I managed to just link my button to the blog index for said category and that is fine for now...
  • Hi Morgancreative

    Hi, in order to have a button that dynamically links to whatever may be the latest post, you would have to do this by php, since the post id is always changing, and so you need to execute a function to determine the latest post id, within the button parameters.

    But of course you can easily specify a category, since that is a permanent hyperlink. Every individual post has a permalink as well, so you could modify the button code each time you post - its a touch extra work, but not to much.

    Maybe Lin will come up with something additional, but that's what occurs to me at this late hour of the evening (12:30am and counting).

    Happy Striking
    Websys Team
    James
  • Thanks! I did find info on calling results:

    http://keirwhitaker.com/archive/wordpress-get-latest-post-url-function/

    and will review this in more detail soon.
  • Hi todd

    And I think you likely realize what you see there is similar to the type of code Striking incorporates already in droves in order to provide the ability for users to sort in the gazillions of ways provided in the theme (think of all the categories in the blog, portfolio and slider shortcodes, and how you can sort and choose by this that and the other thingy).

    Its the button part part together with the php. Think of the Read more button - there is a whole script in the background in order for that to work, to that specific post. Buttons go to a stationary target, either by way of a fixed link, or php code to help them find that fixed link (read more button). Trying to make it dynamic, and fit with the button on a usable basis, so that any button can be set to pick up any dynamic target, that's the challenge.

    Someone somewhere may have spent the time to write a script to accomplish this, but I have not found it. In his example, he is listing links, rather then buttons.

    Still, once we get through the next period of time (there are still 2 more WP releases leading to wp 4.0 on the immediate horizon) we will have a look, if genius does not strike on your end first.

    Best Regards
    Websys Team
    James (who is definitely ready for bed!)
  • OK. That's for the heads up. If I find a solution over the weekend will post here?
This discussion has been closed.
All Discussions