Skip to:
Content
Pages
Categories
Search
Top
Bottom

showing topics from separate sites – need formatting help


  • Jerry
    Participant

    @jerrysc

    I have been working for about 5 days to get topics from a forum on one site to show on my main page, which is a separate site. I’m running current versions of wordpress multisite, bbpress, and buddypress on my main page.

    I found some code via my searches and created a simple plugin. It works to display topics from a separate site on my main page. That was a victory for sure. The problem I am now having is the formatting! Arrghh! I cannot get it to format correctly.

    I know that others have been wanting to do this, so perhaps someone else can get me to the final step and we can publish a good plugin. Here is the code:

    <?php
    /* 
    		Plugin Name: Recent bbpress Topics
    		Plugin URI: http://whosgotbooks.com/wp-content/plugins
    		Description: A plugin to display recent bbpress topics across the network
    		Version: 1.0.0
    		Author: Jerry Caldwell
    		Author URI: http://whosgotbooks.com
    		License: Open Source 
    */ 
    
    function recent_bbpress_topics_shortcode() {                  
      recent_bbpress_topics(); }
      add_shortcode( 'recent-bbpress-topics', 'recent_bbpress_topics_shortcode' );
    
    // ! // Add Recent Topics to BBPress
    function recent_bbpress_topics() {
      if ( bbp_has_topics( array( 'author' => 0, 'show_stickies' => false, 'order' => 'DESC', 'post_parent' => 'any', 'posts_per_page' => 8 ) ) ) { 
          //bbp_get_template_part( 'bbpress/loop', 'topics' );
          bbp_get_template_part( 'loop', 'topics' );
          }
    // Hook into action
    add_action('bbp_template_after_forums_loop','recent_bbpress_topics');
    
    } ?>

    I have been trying to get this to format with bbpress.css. I managed to changed the css on one of my sites to get things how I want, but I can’t with this function. Here is a link of how I want things to look: http://whosgotbooks.com/book-reviews/
    And here is the link of the main page, where I can’t quite get it the way I want it: http://whosgotbooks.com/

    Here is the bbpress.css that worked on the review page, but doesn’t work for the main page:

    li.bbp-topic-title {
    	float: left;
    	text-align: left;
      overflow: hidden;
    	width: 75%;
    }
    #bbpress-forums li.bbp-body ul.topic {
    /*	border-top: 1px solid #7D573A; */ 
      border-top: transparent;
    	overflow: hidden; 
      display: inline-table;  
    	padding: 8px;
      width: 22%;
    }

    To get the books somewhat organized on the main page, I had to change width to 20% on the bbp-topic-title class above, and the bbp-body ul.topic changes do not help on the main page.
    This is the extent of my abilities. I would love to get rid of those annoying dots as well. Hopefully someone can help me get the rest of the way.
    Thanks…

Viewing 19 replies - 1 through 19 (of 19 total)

  • Robin W
    Moderator

    @robin-w

    ok,

    the dots are coming from your style.css line 118

    ul {
    list-style: disc outside none;
    }

    change to

    ul {
    list-style: none outside none;
    }

    although you may need to make this forum specific.


    peter-hamilton
    Participant

    @peter-hamilton

    #content ul ul

    needs padding:0

    and list-style:none

    Thats it mate


    Robin W
    Moderator

    @robin-w

    @peter-Hamilton – great, knew someone who is better at css would come along !


    Jerry
    Participant

    @jerrysc

    Thanks Robin! Thanks Peter! After some trouble-shooting, the answer is as follows:

    #content ul {
    padding: 0;
    margin-left: 0;
    list-style: none;
    }

    For some reason, if I use “ul” twice after “#content”, it doesn’t quite work.
    I was using firebug, and had identified line 118 in style.css, but just didn’t make the exact connection on how to change it. I used firebug again this morning, and learned how to use it better, so thanks for leading me to a great lesson!
    Robin; if you want to make this into a plugin where the user gets some options on the back-end, I will be happy to help with the grunt work and you can post it and get the credit. Just let me know, and give me some direction.
    Thanks again…

    PS For anyone who uses this code, I made the css changes in my style.css within my Child Theme, not the main style.css.


    Jerry
    Participant

    @jerrysc

    Update on this. It turns out my code was insufficient. If have fixed it, sort of, which has led to another problem. First, here is the updated code:

    <?php
    /* 
    		Plugin Name: Recent bbpress Topics
    		Plugin URI: http://whosgotbooks.com/wp-content/plugins
    		Description: A plugin to display recent bbpress topics across the network
    		Version: 1.0.0
    		Author: Jerry Caldwell
    		Author URI: http://whosgotbooks.com
    		License: Open Source
    */ 
    function recent_bbpress_topics_shortcode() {                  
      recent_bbpress_topics(); }
      add_shortcode( 'recent-bbpress-topics', 'recent_bbpress_topics_shortcode' );
    
    //Add Recent Topics to BBPress
    function recent_bbpress_topics() {
    	switch_to_blog(9);
      if ( bbp_has_topics( array( 'author' => 0, 'show_stickies' => false, 'order' => 'DESC', 'post_parent' => 'any', 'posts_per_page' => 7 ) ) ) { 
          bbp_get_template_part( 'bbpress/loop', 'topics' );
          }
    // Hook into action
    add_action('bbp_template_after_forums_loop','recent_bbpress_topics');
    } ?>

    Using the line “switch_to_blog(9);” works great to get the topics from site 9 to the main site. But now my problem is; it brings some unwanted behavior. The main content looks great, but the sidebars change to the format of site 9. Perhaps this has become a wordpress issue and not a bbpress issue? Perhaps I need to use code in addition to “switch_to_blog(9);” that prevents the unwanted behavior? If I need to change this to a wordpress thread, please let me know and I will. Otherwise, if you can provide a solution, that would be great.


    Jerry
    Participant

    @jerrysc

    Got it solved! First, sorry for all the responses. I got lazy in posting the above instead of searching for the solution in the wordpress codex first. Turns out there is a function to return to the current blog, which I inserted within the “if” statement. Specifically, it is “restore_current_blog();”. Here is the working code:

    <?php
    /* 
    		Plugin Name: Recent bbpress Topics
    		Plugin URI: http://whosgotbooks.com/wp-content/plugins
    		Description: A plugin to display recent bbpress topics across the network
    		Version: 1.0.0
    		Author: Jerry Caldwell
    		Author URI: http://whosgotbooks.com
    		License: Open Source
    */ 
    /*
    Here is the shortcode required [recent-bbpress-topic]
    */
    function recent_bbpress_topics_shortcode() {                  
      recent_bbpress_topics(); }
      add_shortcode( 'recent-bbpress-topics', 'recent_bbpress_topics_shortcode' );
    
    //Add Recent Topics to BBPress
    function recent_bbpress_topics() {
    		switch_to_blog(9);
      if ( bbp_has_topics( array( 'author' => 0, 'show_stickies' => false, 'order' => 'DESC', 'post_parent' => 'any', 'posts_per_page' => 7 ) ) ) { 
          bbp_get_template_part( 'bbpress/loop', 'topics' );
          restore_current_blog();
          }
    // Hook into action
    add_action('bbp_template_after_forums_loop','recent_bbpress_topics');
    } ?>

    For anyone who wants to use this, a few more points. One, don’t forget the formatting for style.css. Two, I changed that formatting within a child theme. Three, I can’t guarantee you will have the same results with your formatting as I have made many other formatting changes the past few months for my site. Lastly, I did not “network activate” my plugin. I only activated it on the main site.
    As I get time I will add comments and try to increase the functionality of this plugin. Right now it is very basic. Maybe I’ll get good enough to publish it?


    Robin W
    Moderator

    @robin-w

    Hey never apologise for posting interim solutions – great to see your workings and thinking.

    Any plugin that works is good enough to be published, my first was very basic !

    Can you post your final css please, it can be wrapped into the plugin so that it becomes a package.


    Jerry
    Participant

    @jerrysc

    All css changes are within my child theme. For my child-theme’s style.css, I added this at the very bottom:

    /*Changes made to accommodate plugin recent-bbpress-changes*/
    #content ul {
    padding: 0;
    margin-left: 0;
    margin-right: 0;
    list-style: none;
    }

    For my bbpress.css in my child-theme, I added this around line 158 or so:

    li.bbp-topic-title {
    	float: left;
    	text-align: left;
    	width: 20%;

    One note on bbpress.css. The original bbpress.css had some combined lines that I separated. For example, I think that li.bbp-topic-title was combined with li.bbp-forum-info, as in the following manner:

    li.bbp-forum-info,
    li.bbp-topic-title {
    	float: left;
    	text-align: left;
    	width: 20%;

    But I could be wrong. Doesn’t matter. Separating them appears to be just fine.


    Robin W
    Moderator

    @robin-w

    ok thanks for that, I’ll see what’s needed.

    The original bbpress will group together things, you child theme can then pick and change individuals.

    So for instance if you were describing your family in a style.css you might have

    mother, daughter 1, daughter 2 {
    wearing : dress
    }
    father, son {
    wearing : jeans
    }

    Say you decided that daughter 2 should have tshirt and jeans, so in your child theme you’d put

    daughter 2 {
    Wearing : tshirt&jeans ;
    }

    This will leave mother and daughter 1 as they were and only change daughter 2

    silly example, but hopefully explains !


    Jerry
    Participant

    @jerrysc

    Hi Robin. I made another improvement and added some comments. I noticed that, no matter where I inserted the shortcode, the topics displayed at the top of the content. After some searching I learned why – functions need to return a string. So I found an easy wordpress solution. I also simplified the shortcode, and removed the add_action line at the bottom as it was not doing anything. Here is the updated code:

    add_shortcode( 'recent-bbpress-topics', 'recent_bbpress_topics' );
    
    // Add Recent Topics to BBPress from separate site within WP Multisite
    function recent_bbpress_topics($attr) {
        //Switch to the blog where the bbpress topics are located
        switch_to_blog($attr['id']);
        //this, along with $response variable below, allows for display within content - without these, shortcode will display topics at top of content
        ob_start();
      if ( bbp_has_topics( array( 'author' => 0, 'show_stickies' => false, 'order' => 'DESC', 'post_parent' => 'any', 'posts_per_page' => 9 ) ) ) { ?> 
          <?php bbp_get_template_part( 'bbpress/loop', 'topics' );
          //restore the current blog to maintain formatting
          restore_current_blog();
          }
          //this, along with ob_start(); above, allows for display within content, instead of at the top of the content/page
          $response = ob_get_contents();
            ob_end_clean();
            return $response;
    }

    smsbartar
    Participant

    @smsbartar

    @Jerry thanjs u a lot
    I have this problem tooo And i solve it with your advise !
    thank u alot.


    Jerry
    Participant

    @jerrysc

    I have updated the code again, and I have a question to improve it a little. First the update; I had more trouble with formatting when I wanted to bring in topics from different sites. What I finally learned was to create a new id class and use it in my child theme style.css. Here is the updated code:

    add_shortcode( 'recent-bbpress-topics', 'recent_bbpress_topics' );
    
    // Add Recent Topics to BBPress from separate site within WP Multisite
    function recent_bbpress_topics($attr) {
    	//Switch to the blog where the bbpress topics are located
      switch_to_blog($attr['id']);
    
      //this, along with $response variable below, allows for display within content - without these, shortcode will display topics at top of content
      ob_start();
      if ( bbp_has_topics( array( 'author' => 0, 'show_stickies' => false, 'order' => 'DESC', 'post_parent' => 'any', 'posts_per_page' => 8 ) ) ) {
        //id class to be named "#recent-titles li.bbp-topic-title" and placed in style.css in the child theme ?>  
        <ul id="recent-titles">
          <?php while ( bbp_topics() ) : bbp_the_topic(); ?>
    			<?php bbp_get_template_part( 'loop', 'single-topic' ); ?>
    		  <?php endwhile; ?>
          <?php //bbp_get_template_part( 'loop', 'topics' ); ?>
        </ul>
        <?php //restore the current blog to maintain formatting 
        restore_current_blog();
        }
        //this, along with ob_start(); above, allows for display within content, instead of at the top of the content/page
        $response = ob_get_contents();
          ob_end_clean();
          return $response;
      }

    And here is what I added to style.css:

    /*Changes made to accommodate formatting for plugin recent-bbpress-changes*/
    #recent-titles li.bbp-topic-title {
    	float: left;
    	text-align: left;
    	width: 12%;
      overflow: hidden;
    }

    Notice how I declared the class id in the php code. One additional note; I have made several changes to my bbpress topics before I ever implemented this plugin. Perhaps other users will not require the css changes that I had to implement, post plugin activation.

    Now for my question: Is it possible to have two input parameters to a shortcode? For this plugin, I would like to be able to change the input to “post_parent” as well as “switch_to_blog($attr[‘id’]);”. I’ve already tried to do this, but have failed. Here is what I tried:

    function recent_bbpress_topics($attr,$attr2) {
    	//Switch to the blog where the bbpress topics are located
      switch_to_blog($attr['id']);
    
      //this, along with $response variable below, allows for display within content - without these, shortcode will display topics at top of content
      ob_start();
      if ( bbp_has_topics( array( 'author' => 0, 'show_stickies' => false, 'order' => 'DESC', 'post_parent' => $attr2['id2'], 'posts_per_page' => 8 ) ) )

    I end up getting an illegal string swap error. Anyone got any ideas here?


    Robin W
    Moderator

    @robin-w

    can you post the exact error please ?


    Jerry
    Participant

    @jerrysc

    Hi Robin. I’m on my way to the UK to support the Farnborough airshow, so I can’t access my home computer to replicate the error for another week. What I can tell you is; when I removed the switch_to_blog id input parameter and instead assigned a variable $cat to ‘post_parent’, and set $cat = $attr[‘id’];, I received no errors. I hard-coded to the blog site, then I can adjust the id to equal the forum id. So my feeling is that shortcodes cannot accept two inputs? If I’m wrong about that, then I will re-address this upon my return to the states.


    Robin W
    Moderator

    @robin-w

    hey no problem, just post the details when you get back


    Jerry
    Participant

    @jerrysc

    Hi Robin. Finally getting around to posting the error I see when trying to use two input parameters for a shortcode:
    Warning: Illegal string offset 'id2' in /mysite/wp-content/plugins/recent-books-discussed/recent-books-discussed.php on line 33

    I should probably start a different thread in the forums on this?


    Robin W
    Moderator

    @robin-w

    no, we can carry on here !

    I have to say I’m not sure whether it can take two, the codex seems to think it can be passed 2in the examples.

    https://codex.wordpress.org/Function_Reference/add_shortcode

    However you are passing an array $attr to the function, so why cant you just pass two elemenstb within that array

    $attr[‘id’]
    and
    $attr[‘id2’]


    Jerry
    Participant

    @jerrysc

    Hi Robin. Sorry for the delayed response. It worked! Thanks for the simple fix. Now we know that shortcodes can take two inputs. If you need any of my code for use in a plugin, let me know. Though I have done things that are unique to my website, so they may not be as useful.

    We can close this thread now.


    Robin W
    Moderator

    @robin-w

    Jerry, great – glad you’re fixed !

Viewing 19 replies - 1 through 19 (of 19 total)
  • You must be logged in to reply to this topic.
Skip to toolbar