Skip to:
Content
Pages
Categories
Search
Top
Bottom

Homepage other than Activity or Admin Blog (or a WP page)

  • @stwc

    Participant

    This may be one of those things where the answer is obvious and my brain is locking up again, but I’ve been trying to figure out how to have the default front page (set in the Dashboard under Settings–>Reading) to be other than

    a) The Activity Stream

    b) The Admin Blog

    c) A WordPress Page

    In other words, I’d like to have visitors land on, say, the Buddypress Groups page or the Forums page or the Blogs page.

    Altering the order of the nav items in header.php in my child theme makes one of those appear first in the navigation tabs list, of course, but people landing on the site still see the Activity stream first (which is how I have it set in Settings–>Reading).

    Thanks!

Viewing 25 replies - 1 through 25 (of 44 total)
  • @xevo

    Participant

    Just put a redirect in bp_init?

    @stwc

    Participant

    Perhaps you could take pity and offer just the tiniest fragment of a hint on how I might do such a marvelous thing? ;-)

    @xevo

    Participant
    function xe_redirect() {
    wp_redirect('http://www.example.com');
    }
    add_action( 'bp_init', 'xe_redirect' );

    Try that, offcourse change the link into whatever you want it to be.

    (place in functions.php)

    @xevo

    Participant

    Whoops, forgot a little thingie. :)

    function xe_redirect() {
    if (bp_is_front_page()) {
    wp_redirect('http://www.example.com');
    }
    }
    add_action( 'bp_init', 'xe_redirect' );

    @stwc

    Participant

    You are a gentleman and a scholar, sir.

    Edit: You are still a gentleman and a scholar, but that didn’t work for me. Gave me a place to start, at least, though. Thanks!

    @xevo

    Participant

    Mhm, thought it wouldn’t work right away.. what ever does?

    Anyway, perhaps wp_redirect just isn’t firing.

    function xe_redirect() {
    if (bp_is_front_page()) {
    header("Location: http://www.example.com/");
    }
    }
    add_action( 'bp_init', 'xe_redirect' );

    And if that doesn’t work, let your site jump off the roof and try this.

    function xe_redirect() {
    header("Location: http://www.google.com/");
    }
    add_action( 'bp_init', 'xe_redirect' );

    @stwc

    Participant

    Thanks for continuing to help, Xevo. Still no joy with either of those options, though!

    @jivany

    Participant

    You may need to bump the priority up:

    add_action( 'bp_init', 'xe_redirect',1 );

    Maybe the redirect isn’t getting called soon enough and something else is sending the header already.

    @stwc

    Participant

    Hmm. Doesn’t seem to like a numeric parameter:

    Parse error: syntax error, unexpected T_LNUMBER in D:/xampp/htdocs/testsite/wp-content/themes/bp-childtheme/functions.php on line 41

    using

    function xe_redirect() {
    if (bp_is_front_page()) {
    header("Location: http://localhost.localdomain/testsite/members/");
    }
    }
    add_action( 'bp_init', 'xe_redirect' 1);

    @jivany

    Participant

    Need a comma in there before the 1. ;)

    @stwc

    Participant

    Oh good lord I need more coffee. *hides in shame*

    Error gone, of course: still no joy, though.

    @jivany

    Participant

    WTF? Are you getting any sort of PHP errors from that? Spitting out a header should work or cause PHP to barf it’s “can’t modify headers already sent” error.

    Maybe toss a debugging echo in there to see if the function is even getting triggered on bp_init.

    @stwc

    Participant

    Echoing some debug text (if I’m doing it right) doesn’t spit anything out, so I guess it’s not getting triggered. No errors in Apache error log, no PHP errors on page load.

    Here’s the function from functions.php

    function xe_redirect() {
    echo ("<h1>HELLO I AM YOUR FRIENDLY REDIRECT FUNCTION</h1>");
    if (bp_is_front_page()) {
    header("Location: http://localhost.localdomain/testsite/forums/");
    }
    }
    add_action( 'bp_init', 'xe_redirect',1 );

    I am bewildered.

    @jivany

    Participant

    Some days I’m a little slow. We already have an example of this in bp-default with the ability to select either the activity stream or blog posts as the front page. Unfortunately I’m not quite understanding the flow through the various hooks and filters right now. I think what you need to ultimately do is something like the following:

    locate_template( array( 'groups/index.php' ), false );

    In bp-default, this is done (well, with activity/index.php) in a function that filters page_template.

    This should be really simple and if you can crack the egg, it opens up the ability to set any page as the front page.

    @r-a-y

    Keymaster

    @stwc

    In your function, try using is_front_page() or is_home() instead of bp_is_front_page().

    @jivany

    Participant

    Yeah, you’re going to have to do the locate_template option. If you really want your Forums (or whatever) to be the front/home page of your site, redirecting will not quite achieve that. It will basically remove your home page at http://example.com and replace it with http://example.com/forums/ so your site will get bookmarked and linked to as http://example.com/forums/ instead. There will be no “root” page.

    Does that make sense? I’m not sure if it makes sense to me the way I’ve written it. ;)

    @stwc

    Participant

    In your function, try using is_front_page() or is_home() instead of bp_is_front_page().

    @r-a-y Tried those, no luck, again.

    @jivany, thanks, but I’m not really following how to use the

    locate_template( array( 'groups/index.php' ), false );

    stuff either.

    Pretty much ready to give up on it at this stage! Seems like it ought to be an easier thing than it is, but that’s usually the way of things…

    @anointed

    Participant

    This is going to sound really nuts, but it works for me.

    I start by adding a file to my theme with the following:

    /*
    Template Name: Page-Redirect
    */

    if (function_exists('have_posts') && have_posts())
    {
    while (have_posts())
    {

    // get the post
    the_post();

    // get content
    ob_start();
    the_content();
    $contents = ob_get_contents();
    ob_end_clean();

    // correctly build the link

    // grab the 'naked' link
    $link = trim(strip_tags($contents));

    // work out
    if(! preg_match('%^http://%', $link))
    {
    $host = $_SERVER['HTTP_HOST'];
    $dir = dirname($_SERVER['PHP_SELF']);
    $link = "http://$host$dir/$link";
    }

    // navigate to the link
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: $link");
    exit;

    }

    }

    All I have to do then is create a new page, assign the Page-Redirect template to the page and the magic works by simply adding a url to the content area.

    What it gives me is a page that when accessed immediately redirects to whatever link you put in the content. ‘you do not need http stuff just the path to the page like — groups/

    Because it’s a true wp page, now you can select that page in your settings for the homepage.

    like I said, very hacky but it works for now. Hope it helps

    @r-a-y

    Keymaster

    @stwc

    Haven’t tried this, but try using the get_header action, instead of bp_init.

    It comes later in the action list and parses info just before any output to the page is done, so there’s a chance bp_init might be too early.

    @stwc

    Participant

    Anointed’s method works…. aaaalllllmost. Redirection on loading the site, to the URL specified in the post body of the page created using his template happens nicely after modifying Settings-Reading to use that page as the Front page.

    Only problem is now there are TWO Activity tabs in the navigation — one that points to the site root, and one that points to siteroot/activity.

    Oh my poor brain.

    @mercime

    Participant

    Very simple way – assuming you’re using a child theme of bp-default

    1. create and add home.php

    2.a. paste either of following in home.php and upload to server

    – forums directory on front page

    <?php locate_template( array( ‘forums/index.php’ ), true ); ?>

    – groups directory on front page

    <?php locate_template( array( ‘groups/index.php’ ), true ); ?>

    – blogs directory on front page

    <?php locate_template( array( ‘blogs/index.php’ ), true ); ?>

    OR

    2. b. paste required code in home.php and upload to server –

    – forums directory on front page – copy from here

    – groups directory on front page – copy from here

    – blogs directory on front page – copy from here

    3. Delete the link (forums or blogs or groups) from header.php navigation div to avoid duplication

    @stwc

    Participant

    I continue to appreciate everyone’s help with this.

    mercime, what do you mean by ‘add home.php’?

    Sorry, it’s been a long, tiring day. I feel like I’m actively learning less about this stuff every day, rather than more.

    @mercime

    Participant

    No worries, I should have been clearer. You create a new file called home.php and insert the codes from 2.a. or 2.b and save that file in your bp-default child theme folder in hard drive and upload to server to your bp-default child theme folder there..

    @jivany

    Participant

    @mercime: Is it really that simple?!? *Groan*

    @modemlooper

    Moderator

    home.php overrides the front page only if the readings settings are in default state. If you have chosen a different front page in admin settings. home.php will not work.

    I’m going through a similar problem with a mobile theme. Trying to get a front page forced, haven’t found a solution yet.

Viewing 25 replies - 1 through 25 (of 44 total)
  • The topic ‘Homepage other than Activity or Admin Blog (or a WP page)’ is closed to new replies.
Skip to toolbar