Support » Fixing WordPress » add body of blog post on main page or in widget?

  • my site is a gym and they post workouts every day , it is posted in blog format. is there any way to post the blog contents in the form of a widget? can anyone provide a suggestion on how to achieve this.

Viewing 15 replies - 1 through 15 (of 16 total)
  • So you want to have the name of the blog post in the widget? Can you give us some more information and maybe a link to your site to show us an example of a workout post?

    Thread Starter rsix08

    (@rsix08)

    here is the post
    http://www.crossfit1066.com/wod-december-3-2013/

    would like the body text to appear in the widget , there will be a new post daily so would like it to change each day

    Widgets are by default in the sidebar which I assume you know.

    You can download this plugin: http://wordpress.org/plugins/enhanced-text-widget/

    Activate the plugin and drop the widget in the sidebar that you want. Create a tag, let’s say ‘workouts’, and add the posts to it then add this code in the Enhanced Text Widget:

    <?php
    
    $args = ('tag' => 'workouts' , 'posts_per_page' => 1);
    
    // The Query
    $the_query = new WP_Query( $args );
    
    // The Loop
    if ( $the_query->have_posts() ) {
    	while ( $the_query->have_posts() ) {
    		$the_query->the_post();
    		echo get_the_title();
                    echo get_the_content():
    	}
    } else {
    	// no posts found
    }
    /* Restore original Post Data */
    wp_reset_postdata();
    
    ?>
    Thread Starter rsix08

    (@rsix08)

    first i want to say thank you for your help

    I have installed the plugin and added the code but it does not display an text.
    what I would like to do is display the last blog post body text from the “wod” category.

    Thread Starter rsix08

    (@rsix08)

    i have changed ‘workout’ to ‘wod’ and added to wod to the tag of one of the posts still blank

    My bad, this works and I’ve tested it:

    <?php
    
    $args = array('tag' => 'workouts' , 'posts_per_page' => 1);
    
    // The Query
    $the_query = new WP_Query( $args );
    
    // The Loop
    if ( $the_query->have_posts() ) {
    	while ( $the_query->have_posts() ) {
    		$the_query->the_post();
    		echo get_the_title();
                    echo get_the_content();
    	}
    } else {
    	// no posts found
    }
    /* Restore original Post Data */
    wp_reset_postdata();
    
    ?>
    Thread Starter rsix08

    (@rsix08)

    I added the new code but it is still blank would you be able to look at my page it is the bottom left widget in the footer

    Did you change the tag workouts in my code to the tag you want to use? It’s working for me.

    Thread Starter rsix08

    (@rsix08)

    <?php

    $args = array(‘tag’ => ‘wod’ , ‘posts_per_page’ => 1);

    // The Query
    $the_query = new WP_Query( $args );

    // The Loop
    if ( $the_query->have_posts() ) {
    while ( $the_query->have_posts() ) {
    $the_query->the_post();
    echo get_the_title();
    echo get_the_content();
    }
    } else {
    // no posts found
    }
    /* Restore original Post Data */
    wp_reset_postdata();

    ?>

    Thread Starter rsix08

    (@rsix08)

    yes have also added wod tag to the post

    Thread Starter rsix08

    (@rsix08)

    is it possible that there may be spaces when im copying/pasting that is messing up the syntax

    Thread Starter rsix08

    (@rsix08)

    the tag under posts has a slug of wod-2 so im thinking wod is used somewhere else and that looks like the issue but im still looking into it. but i was able to add the tag wod to my posts

    Thread Starter rsix08

    (@rsix08)

    it looks like that was the problem thanks for your help , just another quick question. the post is displayed in paragraph format is there anyway to get it to display similar to the post which looks a little neater

    Just check what styles are used for the posts that you want it to look like and add those classes/id’s to the code.

    Thread Starter rsix08

    (@rsix08)

    hi thank you for your reply, im not sure what you mean I am fairly new to wordpress. this is how it looks in the post:

    Workout of the Day
    A.
    Three sets of:
    Front squat x 6-8 reps @ 30X1
    Rest 45 seconds
    Single-Arm Dumbbell Row x 8-10 reps @ 2111 each arm
    Rest 45 seconds
    Plank from Elbows x 45 seconds
    Rest 45 seconds

    B.
    Five sets for max calories/reps of:
    30 seconds of Rowing (for max calories)
    30 seconds of Rest
    60 seconds of Kettlebell Swings
    Rest 2 minutes

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘add body of blog post on main page or in widget?’ is closed to new replies.