WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Appending links with variables, in the calendar and elsewhere (3 posts)

  1. jthomasc
    Member
    Posted 7 years ago #

    I have a site that has it's own content management system.
    I am using data in that system to build user pages.

    The design calls for the blog to be inline in one of these pages for each user. I am thinking I would use the author var to display that users posts on each of their respective pages.

    So an example of an initial link to a user blog is http://www.mysite.com/blog/?author=1&user=2 where the author pulls from the wordpress DB and the user from my CMS, but the links that flow within that off the titles and the add comment and to other posts I need to append the &user=2 so that the correct information for that user appears on the page.

    Now I have had success using php to append that to the links I have access to in the template pages but the design includes taking advantage of the get_calendar() aspect of wordpress.

    I am wondering if it possible to get at the links generated in that so I can append the user id to maintain the CMS aspect of the site through those links.

    Also I am not the most experienced php programmer, so go easy on me.

    Thanks for any help you can offer.

  2. Kafkaesqui

    Posted 7 years ago #

    It would create a tiny bit of overhead to process, but one method is to use PHP's output buffering to capture the output of the WordPress function, then use a little pattern matching to attach your query string addition to any url.

    The following *should* work, though it might be painful...:)

    <?php
    ob_start();
    get_calendar();
    $user_calendar = ob_get_contents();
    ob_end_clean();

    $user_calendar = preg_replace('/(<a href=".*)"/U', '\\1' . "&user=$USERID" . '"', $user_calendar);

    echo $user_calendar;
    ?>

    In summary the code 1. puts the output of get_calendar() in $user_calendar, 2. uses preg_replace to add &user=$USERID to each url, and 3. displays the calendar. $USERID would be replaced with what you're using to assign the 'user' query value.

  3. jthomasc
    Member
    Posted 7 years ago #

    Thank you so much, that worked like a charm.
    Mark this question resolved.

    Very much appreciated.

    J.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags