Support » Fixing WordPress » Load a single post as homepage

  • Hi

    This sounds simple, but to explain, I’d like to know if it’s possible to load the latest post as the front page, rather than run a query that only returns the latest post if that makes sense.

    Reason is, I’m using a script that loads a post’s custom css (if it exists) and if I only return a single post through a query, it doesn’t load.

    Hope this makes sense.



Viewing 7 replies - 1 through 7 (of 7 total)
  • What’s the difference in loading the last page and running a query that returns the last post? That kind of is the same…
    Could you explain that in more detail?

    It sounds like you’r looking for a way to adjust your loop on index.php, or want to use a static homepage.

    Hi dhunink

    Sorry if it wasn’t clear. I’m using a script I found at ‘Digging into WordPress’, and it allows you to reference a custom css file when you’re putting the post together.

    Problem is, it only loads the custom css file once you’ve clicked on the link. If <?php the_content(); ?> is referenced in the home page (minus the css) it looks cack, as it’s using the default css.

    Does that make sense?


    May sound kind of stupid, but why wouldn’t you include the custom css file in the header? All of the posts will be affected then.

    Maybe it helps if you could share some of your code with us. Rember to put the code between backticks.

    As potentially going forward, they’ll be a fair few custom css files, and I don’t want to load them all when they’re not required.

    Could you share the script you’ll using now?

    Maybe an idea to rewrite the script, which loads a certain css file when a certain condition is present. Could help you out with that

    // Custom Stylesheet box in Pages/Posts
    add_action('admin_menu', 'digwp_custom_css_hooks');
    add_action('save_post', 'digwp_save_custom_css');
    function digwp_custom_css_hooks() {
    	add_meta_box('custom_css', 'Name of custom CSS file', 'digwp_custom_css_input', 'post', 'normal', 'high');
    	add_meta_box('custom_css', 'Name of custom CSS file', 'digwp_custom_css_input', 'page', 'normal', 'high');
    function digwp_custom_css_input() {
    	global $post;
    	echo '<input type="hidden" name="custom_css_noncename" id="custom_css_noncename" value="'.wp_create_nonce('custom-css').'" />';
    	echo '<input type="text" name="custom_css" id="custom_css" style="width:100%;" value="'.get_post_meta($post->ID,'_custom_css',true).'" />';
    function digwp_save_custom_css($post_id) {
    	if (!wp_verify_nonce($_POST['custom_css_noncename'], 'custom-css')) return $post_id;
    	if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
    	$custom_css = $_POST['custom_css'];
    	update_post_meta($post_id, '_custom_css', $custom_css);
    function digwp_insert_custom_css() {
    	if (is_page() || is_single()) {
    		if (have_posts()) : while (have_posts()) : the_post();
    		  $filename = get_post_meta(get_the_ID(), '_custom_css', true);
    		  if ($filename) {
    			echo "<link rel='stylesheet' type='text/css' href='" . get_bloginfo('template_url') . "/css/" . $filename . "' />";
    		endwhile; endif;

    Maybe me misunderstanding, but what happens when you ad <?php the_content(); ?> inside the loop of digwp_insert_custom_css()?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Load a single post as homepage’ is closed to new replies.