WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Page name hook? (5 posts)

  1. Davy27
    Member
    Posted 7 years ago #

    I've created a page titled 'Portfolio' with slug 'portfolio', is there a hook to 'pull the 'portfolio' part from the below URL?

    davy27.neoburn.net/portfolio/

    I'm creating my first plugin and I've not touched PHP in 3 years so this may be a silly question, but I can't seem to find much from WP documentation.

    Thanks for your time =)

  2. Kafkaesqui

    Posted 7 years ago #

    The $post object provides the property:

    $post->post_name

    Typically, scoping $post to global will make all of a post's table records available to your plugin.

  3. Davy27
    Member
    Posted 7 years ago #

    I just echo'd $post and it doesn't show.

    add_filter('the_content', 'DEPortfolio_the_content');

    function DEPortfolio_the_content($content)
    {
    $content = 'I am the content. Marvel at my simplicity!' . $post;
    return $content;
    }

    I've got this horrible feeling I'm handling this from the wrong direction. I want to have a blog on the index, but on the portfolio page I want to list all blog entries with category 'portfolio'. I figured I could use a plugin and filter out all the unnecessary parts then format the posts I want then echo it all back onto the page.

    Would I be able to do this via plugin?

  4. Kafkaesqui

    Posted 7 years ago #

    First, $post would be an array (or rather, an object). So it should be more like:

    $content = 'I am the content. Marvel at my simplicity! ' . $post->post_content;

    Also note I said you need to scope $post to global (before using it):

    global $post;

    Finally, return will not actually echo anything. But you knew that, right?

  5. Davy27
    Member
    Posted 7 years ago #

    Yeah I have no idea why I said that about return not echoing. As I understand it, [code]return[/code] just literally 'returns' the outcome of the function to wherever requests it.

    I didn't cover functions much and the complexity of WP is driving me nuts!! The lack of documentation for the hooks doesn't help, either.

    Thank you for the help, I found the solution to my current problem. No doubt I'd need more help in future.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags