Wordpres PHP Help Needed

8 replies
I am trying to get the ID of a particular post that is replicated onto various blogsites in a network.

The code below works to give me the blog ID, but, the blog URL is shown onscreen without the echo command being invoked. What do I need to change?

I have been unable to get it to work without including the blog URL from bloginfo.

Code:
 $ varname = url_to_postid(bloginfo('url') . '/category-slug/post-slug/');
#needed #php #wordpres
  • Profile picture of the author Steve Fleming
    Hi Kirk

    How are the sites related? By that I mean are they all part of the
    same multisite install or are they completely separate blogs? If
    separate blogs, are the blogs all part of YOUR network or do they
    include web 2.0 blogs, for example?

    Steve
    {{ DiscussionBoard.errors[7686038].message }}
    • Profile picture of the author Kirk Ward
      Originally Posted by Steve Fleming View Post

      Hi Kirk

      How are the sites related? By that I mean are they all part of the
      same multisite install or are they completely separate blogs? If
      separate blogs, are the blogs all part of YOUR network or do they
      include web 2.0 blogs, for example?

      Steve
      Hi Steve,

      The blogs are all a part of the same multisite network.

      In this script, I have used the 'switch_to_blog()' function to switch to the main blog (using switch_to_blog(1) ) and then used a selectbox with a foreach loop in it and the 'setup_postdata()' function to build a list of posts from a specific category.

      Then I use the 'restore_current_blog()' function to return to the current blog where the admin can save a copy of the post from the main blog.

      The posts the admin is selecting from could best be described as product sales pages, and the blog admin will be earning a commission on each one he or she sells.

      They select the post from the main blog, and then it is saved to the catalog post spot on their blog. That is how they are related.
      Signature
      "We are not here to sell a parcel of boilers and vats, but the potentiality of growing rich beyond the dreams of avarice."

      Dr. Samuel Johnson (Presiding at the sale of Thrales brewery, London, 1781)
      {{ DiscussionBoard.errors[7689466].message }}
  • Profile picture of the author SteveJohnson
    If you're assigning the output of a function to a variable, the function should return its result. What you're describing is indicative of a function that echoes its result. Verify that your 'url_to_postid' function returns its result.
    Signature

    The 2nd Amendment, 1789 - The Original Homeland Security.

    Gun control means never having to say, "I missed you."

    {{ DiscussionBoard.errors[7686648].message }}
    • Profile picture of the author Kirk Ward
      Originally Posted by SteveJohnson View Post

      If you're assigning the output of a function to a variable, the function should return its result. What you're describing is indicative of a function that echoes its result. Verify that your 'url_to_postid' function returns its result.
      Thanks Steve ...

      RFT16 explained it even further. I had tried to figure that out by reading the codex, and experimenting, but I absolutely did not see the difference until you two pointed it out. RFT16 specifically told me which did what. I tried to figure that out from the codex, but the answer never sunk in until now.

      Thanks again!
      Signature
      "We are not here to sell a parcel of boilers and vats, but the potentiality of growing rich beyond the dreams of avarice."

      Dr. Samuel Johnson (Presiding at the sale of Thrales brewery, London, 1781)
      {{ DiscussionBoard.errors[7689476].message }}
  • Profile picture of the author rft16
    the problem here is probably with your 'bloginfo' function.

    WP generally provides two variants of a single function - one that returns the value and another that echoes the output.

    In this case 'bloginfo( parameter )' ECHOS the value of the parameter.
    Whereas 'get_bloginfo( parameter )' RETURNS the value of the parameter.

    Hope this helps.

    Cheers.
    {{ DiscussionBoard.errors[7687503].message }}
    • Profile picture of the author Kirk Ward
      Originally Posted by rft16 View Post

      the problem here is probably with your 'bloginfo' function.

      WP generally provides two variants of a single function - one that returns the value and another that echoes the output.

      In this case 'bloginfo( parameter )' ECHOS the value of the parameter.
      Whereas 'get_bloginfo( parameter )' RETURNS the value of the parameter.

      Hope this helps.

      Cheers.
      That was the problem. I needed 'get_bloginfo()' instead of 'bloginfo()'

      I had read both of the codex pages, and tried their examples. You gave me the understanding that Wordpress didn't. I guess the folks that write the codex have varying skills, so they are not always as clear in their explanations as beginners like me need.

      Many thanks!
      Signature
      "We are not here to sell a parcel of boilers and vats, but the potentiality of growing rich beyond the dreams of avarice."

      Dr. Samuel Johnson (Presiding at the sale of Thrales brewery, London, 1781)
      {{ DiscussionBoard.errors[7689451].message }}
  • Profile picture of the author RebeccaBaylies
    For the first problem, go to your web page in your browser, right click on the 'x' icon, select properties and read the url that comes up, ensure that the image you want displayed is named exactly as written and located where expected.
    Second problem...let me read it again, i'll get back to you...

    Right, can't help much without seeing the rest of the script, displaying images next to each would be done using html or css, but there's not enough info to advise on the rest of the problem, also, i'm not familiar with wp
    {{ DiscussionBoard.errors[8183613].message }}
  • Give me a call 1-800-219-1314 EXT 0 I'll give you a hand i don't mind.

    let me know if you gotten it fixed or not.

    WILL-
    Signature
    WebDevelopmentGroup NYC & CA- Small Business Web Development, App Development, WordPress Development, Graphic Designs, Online Marketing, Local Marketing & more!. "Call us 1.800.219.1314 or message us!". Visit us today! "Now On Live Chat Mon-Fri.". www.WebDevelopmentGroup.org
    (Whitelable our Services)
    ===================================
    ==> #1 OFFLINE MARKETING FORUM ON THE WEB! <==
    www.OFFLINEMARKETINGFORUM.com
    (Register Now)
    {{ DiscussionBoard.errors[8184787].message }}

Trending Topics