Displaying last post in home page

Hi,

I would like to display the last post in the home page of the site. Just the title, a few lines and a link to the post. Is there any easy way to do that?

Thanks in advance.

Regards.

Ricard Castellet
«1

Réponses

  • In home page, use
    $plxShow->lastArtList('<h2>#art_title</h2><article>#art_chapo</article><p><a href="#art_url" title="#art_title">Read more</a>',1);
    
  • Hii Jerry,

    Thanks for your help. The function you posted should go between php tags like this:

    <?php
    $plxShow->lastArtList('<h2>#art_title</h2><article>#art_chapo</article><p><a href="#art_url" title="#art_title">Read more</a>',1);
    ?>

    Should I make any declaration? Am I missing anything?

    Regards.
  • StéphaneStéphane Member, Former PluXml Project Manager
    Hi

    You just have to copy and paste the code in home.php in your theme folder.
    <?php
    $plxShow->lastArtList('<h2>#art_title</h2><article>#art_chapo</article><p><a href="#art_url" title="#art_title">Read more</a>',1);
    ?>
    

    Consultant PluXml

    Ancien responsable du projet (2010 à 2018)

  • Jerry WhamJerry Wham Member
    février 2014 modifié
    For example, for page home.php from default theme. Instead of :
    <?php include(dirname(__FILE__).'/header.php'); ?>
    
    <section>
    
    	<div id="container">
    
    		<div class="width-sidebar">
    
    			<?php while($plxShow->plxMotor->plxRecord_arts->loop()): ?>
    
    			<article role="article" id="post-<?php echo $plxShow->artId(); ?>">
    
    				<header>
    					<h1>
    						<?php $plxShow->artTitle('link'); ?>
    					</h1>
    					<p>
    						<time datetime="<?php $plxShow->artDate('#num_year(4)-#num_day-#num_month'); ?>"><?php $plxShow->artDate('#num_day #month #num_year(4)'); ?></time>
    					</p>
    				</header>
    
    				<section>
    					<?php $plxShow->artChapo(); ?>
    				</section>
    
    				<footer>
    					<p>
    						<?php $plxShow->lang('CLASSIFIED_IN') ?> : <?php $plxShow->artCat(); ?> -
    						<?php $plxShow->lang('TAGS') ?> : <?php $plxShow->artTags(); ?>
    					</p>
    				</footer>
    
    			</article>
    
    			<?php endwhile; ?>
    
    			<div id="pagination">
    				<?php $plxShow->pagination(); ?>
    			</div>
    
    			<div class="rss">
    				<?php $plxShow->artFeed('rss',$plxShow->catId()); ?>
    			</div>
    
    		</div>
    
    		<?php include(dirname(__FILE__).'/sidebar.php'); ?>
    
    	</div>
    
    </section>
    
    <?php include(dirname(__FILE__).'/footer.php'); ?>
    
    
    Use the code below to do the job :
    <?php include(dirname(__FILE__).'/header.php');?>
    
    <section>
    
    	<div id="container">
    
    		<div class="width-sidebar">
    
    			<article role="article" id="post-<?php $plxShow->lastArtList('#art_id');?>">
    
    				<header>
    					<h1>
    						<?php $plxShow->lastArtList('<a href="#art_url" title="#art_title">#art_title</a>',1);?>
    					</h1>
    				</header>
    
    				<section>
    					<?php $plxShow->lastArtList('<article>#art_chapo</article>',1); ?>
    				</section>
    
    				<footer>
    					<p>
    						<?php $plxShow->lastArtList('<a href="#art_url" title="#art_title">Read more</a>',1);?>
    					</p>
    				</footer>
    
    			</article>
    			
    			<div class="rss">
    				<?php $plxShow->artFeed('rss',$plxShow->catId()); ?>
    			</div>
    
    
    		</div>
    
    		<?php include(dirname(__FILE__).'/sidebar.php'); ?>
    
    	</div>
    
    </section>
    
    <?php include(dirname(__FILE__).'/footer.php'); ?>
    
    
  • Hi Jerry,

    I want the post to appear in the home page of the web (I want to include the blog as part of the web).
    I think I will do with your explanations. Otherwise, I'll will ask for your help again.

    Thanks a lot!!!

    Regards.
  • Hi Stéphane,

    I have tried your code and it works correctly. But what I want is different. I want to leave the home page of the blog as it is. What I want is to show in another page of my website the last post of the blog. And the page I want to show the post in is the home page of the website not the home page of the blog. Hope I have explained well :-)

    Thanks again.
  • 1) In your administration panel, go to static pages.
    Add a new one (choose the name you want, for example index).
    Record.
    Select column "home page" (on left), "active" (yes) and "hide" (on right).
    Record.

    2) In your theme folder, duplicate static.php file, rename the copy as static-home.php and put this code in it :
    <?php include(dirname(__FILE__).'/header.php'); ?>
    
    <?php $plxShow->staticContent(); ?>
    
    <?php include(dirname(__FILE__).'/footer.php'); ?>
    

    3) Go back to your administration panel, static pages, and clic on edit to edit "index" static page.

    4) In the textarea, put this code :
    <?php $plxShow=plxShow::getInstance();?>
    
    <section>
    
    	<div id="container">
    
    		<div class="width-sidebar">
    
    			<article role="article" id="post-<?php $plxShow->lastArtList('#art_id');?>">
    
    				<header>
    					<h1>
    						<?php $plxShow->lastArtList('<a href="#art_url" title="#art_title">#art_title</a>',1);?>
    					</h1>
    				</header>
    
    				<section>
    					<?php $plxShow->lastArtList('<article>#art_chapo(1000)</article>',1); ?>
    				</section>
    
    				<footer>
    					<p>
    						<?php $plxShow->lastArtList('<a href="#art_url" title="#art_title">Read more</a>',1);?>
    					</p>
    				</footer>
    
    			</article>
    			
    			<div class="rss">
    				<?php $plxShow->artFeed('rss',$plxShow->catId()); ?>
    			</div>
    
    
    		</div>
    
    		<?php include(dirname(__FILE__).'/sidebar.php'); ?>
    
    	</div>
    
    </section>
    
    and select the template "static-home.php" you created at step 2.
    Record.

    In sidebar of administrative panel, a new link (blog) at the top of the page (near of back to site) have to be appear.
    If you clic on back to site, you'll go to index page with one article.
    If you clic on blog, you'll go to home page with 5 articles.

    I hope you'll understand my bad english.
  • Hi Jerrry,

    Many thanks. It works fantastically. Just a silly question because the text of the article does not show (?). I can see the title, the "read more", RRS link, etc. everything is fine except for that the text is not visualized. I haver reviewed your code and I think I have made no mistake but I am not able to spot the error. You can have a look if you are so kind here:http://www.bufetepedrola.com/blog/index.php?static2/index

    Thanks in advance. Forgiven for your english :-) Mine is not much better. Regards.
  • Jerry WhamJerry Wham Member
    février 2014 modifié
    Change
    <?php $plxShow->lastArtList('<article>#art_chapo(1000)</article>',1); ?>
    
    with
    <?php $plxShow->lastArtList('<article>#art_content</article>',1); ?>
    

    It's because you didn't write in the "chapo" but in "content".
  • Hi Jerry,

    Done! Many thanks.
    By the way, what is "chapo"?

    Regards
  • The "chapo" is the beginning of an article. It's optional. You can use it as a "header" or a "summary".

    When chapo is used, it appears on home page (with a "read more" link).

    You have two options (when you write a theme) :
    - either it's display before the body of an article on article page
    - or it is not display on the article page, only on home page.

    To write in the chapo, in the administration panel (new article), there is a link (chapo). When is clicked, a textarea appears above the textarea for content.

    If chapo is empty, it is the all content that is display on home page.

    I hope my explanation is understable :P
  • I see. Uderstood. Thanks as always.

    Regards
  • Hi Jerry,

    Your code is working great!

    Just one more question. Last post appears in home page but when I click the title I want it to go to a page (html) that has a document frame with the blog in it. I can go to the page or to the blog but not to the page with the blog in it :-) Any suggestion?

    Many thanks. Regards.
  • Excuse me but I don't understand what you want. Could you explain more please or give a link to your site to see what's happen ?
  • Hi Jerry,

    You can see what I mean here : http://www.bufetepedrola.com/inici2.html
    If you click in the article, it will open the blog page with all the articles (http://www.bufetepedrola.com/blog.html). I have done this way because I don't know how to do that when you click the article in home page, the page that opens is the one of the article (http://www.bufetepedrola.com/blog/index.php?article8/article-6-li-europan-lingues-es-membres-del-sam-familie) directly. This way you can read the full article without having to click again.

    This is important if you want to show in home page articles of a determined category. Then last article of the category shown in the home will not be the last in general in the blog page.

    Hope I have explained.

    Thanks in advance. Regards.
  • Jerry WhamJerry Wham Member
    février 2014 modifié
    Synopsis a lastArtList is :
    public function lastArtList($format='<li><a href="#art_url" title="#art_title">#art_title</a></li>',$max=5,$cat_id='',$ending='', $sort='rsort')
    
    As you can see, you can use only the articles of a category if you define it in the function. So in your case, you want to display the last article of category number 1 (documents). The code will be (in the header of section) :
    <?php include(dirname(__FILE__).'/header.php');?>
    
    <section>
    
    	<div id="container">
    
    		<div class="width-sidebar">
    
    			<article role="article" id="post-<?php $plxShow->lastArtList('#art_id');?>">
    
    				<header>
    					<h1>
    						<?php $plxShow->lastArtList('<a href="#art_url" title="#art_title">#art_title</a>',1,1); //The first 1 is the number of articles to display, the second 1 is the category?>
    					</h1>
    				</header>
    
    etc...
    
  • HI Jerry,

    I see this is the way to display last article of a category in, let's say, home page. Perfect!

    Now, what I want to achieve is to click in this article and go to the blog page and see the article opened (not the list but the article in full). See that my blog is shown in a html page via document frame. So the article url should have the instruction to open the page and then to show the article.

    Thanks as always. Regards.
  • #art_url must give you the url to open in full your article. Is it the case ? Can you paste your code to see what is in your home.php file ?
  • rcastelletrcastellet Member
    février 2014 modifié
    Here you are.

    <?php $plxShow=plxShow::getInstance();?>

    <link rel="stylesheet" type="text/css" href="<?php $plxShow->template(); ?>/style.css" media="screen" />

    <section>

    <div id="container">

    <article role="article" id="post-<?php $plxShow->lastArtList('#art_id');?>">

    <header>
    <h1>
    <?php $plxShow->lastArtList('<a href="http://www.bufetepedrola.com/blog.html" target="_parent" title="#art_title">#art_title</a>',1);?>
    </h1>
    </header>

    <section>
    <?php $plxShow->lastArtList('<article>#art_chapo(1000)</article>',1); ?>
    </section>

    </article>


    </div>

    </section>


    As you see I have an absolute link to the blog page of the web that includes a document frame with pluxml blog in it. If I link to the article, then I go directly to pluxml blog without the parent page.
  • Jerry WhamJerry Wham Member
    février 2014 modifié
    you don't have to add an absolute link on function. Link is generated automaticaly by function. Code of your static home page must be :
    <?php $plxShow=plxShow::getInstance();?>
    
    <section>
    
    	<div id="container">
    
    		<div class="width-sidebar">
    
    			<article role="article" id="post-<?php $plxShow->lastArtList('#art_id');?>">
    
    				<header>
    					<h1>
    						<?php $plxShow->lastArtList('<a href="#art_url" title="#art_title">#art_title</a>',1,1);?>
    					</h1>
    				</header>
    
    				<section>
    					<?php $plxShow->lastArtList('<article>#art_content</article>',1,1); ?>
    				</section>
    
    				<footer>
    					<p>
    						<?php $plxShow->lastArtList('<a href="#art_url" title="#art_title">Read more</a>',1,1);?>
    					</p>
    				</footer>
    
    			</article>
    			
    			<div class="rss">
    				<?php $plxShow->artFeed('rss',$plxShow->catId()); ?>
    			</div>
    
    
    		</div>
    
    		<?php include(dirname(__FILE__).'/sidebar.php'); ?>
    
    	</div>
    
    </section>
    
    Copy and paste it on your statics administration panel page.
  • Hi Jerry,

    If I use #art_url then opens full article in pluxml blog but not in the page of the web where. The instruction should have to be : first, open the blog.html page, then, open the article in full. This is what I don't know how to do. Hope I have explained :-)

    Thanks as always. Regards.
  • Sorry but I don't understand what you want :( .
    (y a pas une âme charitable qui pourrait aider là, car je sèche un peu ?)
  • StéphaneStéphane Member, Former PluXml Project Manager
    @rcastellet: Try to design your site without frames. It is a source of problem and it is difficult to find solutions because this is not the logic of PluXml.

    Consultant PluXml

    Ancien responsable du projet (2010 à 2018)

  • Hi Stéphane,

    I know it is better without frames but it is much easier to integrate your blog via frames. You can see here (http://www.bufetepedrola.com/inici2.html) that it works quite good. The only problem is that when you click in the article url I don't know how to do to open the page blog.html with the article opened. An answer to this would make implementation of PluXml implementation much more flexible.

    Thanks for your help. Regards.
  • I don't think it's much easier to use iframe. If it would be the case, you should not need our help...
    I think the problem is from Serif WebPlus X6. No offense but you should learn html/css instead if you don't known.

    Anyway, what is the file tree of your web site ? Maybe there is a solution without using iframe ?
  • Hi Jerry,

    No offense at all. On the contrary, my gratitude for your help. In fact I should learn html/css but at the moment I can't. Probably I'll do in a near future.
    I know it is better without frames but, as always, it is a long story and the fact is that I am stuck with this :-)
    Serif WebPlus X6 is a good software but not very flexible (they have a blog solution but PluXml is much better).

    I don't know what do you mean by "the file tree of the site". Do you refer a to the structure of the site? It is pretty simple:

    Home
    Blog (testing)
    Equip
    Serveis
    Pràctica Jurídica
    ...
    Documentació
    Contacte


    Thanks again. Regards.
  • StéphaneStéphane Member, Former PluXml Project Manager
    Sorry but again the problem is frames. You can't open

    http://www.bufetepedrola.com/blog/index.php?article8/article-6-li-europan-lingues-es-membres-del-sam-familie

    into the page

    http://www.bufetepedrola.com/blog.html

    by clicking a link from the page

    http://www.bufetepedrola.com/inici2.html

    I'm afraid in this case there will be no solution

    Consultant PluXml

    Ancien responsable du projet (2010 à 2018)

  • I understand. So what is your recomendation to use the blog in the site? What do you think is the better way to do that? Should I copy the necessary html to the index.php page? Please, advice.

    Many thanks. Regards.
  • StéphaneStéphane Member, Former PluXml Project Manager
    Try this way

    1. Add the content of your homepage into a static page
    2. Set this static page as the homepage (you have to check the appropriate checkbox in static pages administration - see column Homepage)
    3. Use a static page template to define the look of the page (in your theme folder make a copy of static.php and name it for example static-homepage.php. Go to the options of your static page and select static-homepage.php in the listbox Template).
    4. Now you can add specific modifications in static-homepage.php to setup the homepage

    Hope this helps

    Consultant PluXml

    Ancien responsable du projet (2010 à 2018)

  • Hi Stéphane,

    I have done the other way round. I have inserted index.php in the html page. No frames. And, for the moment, almost everything goes fine. You can see here: http://www.bufetepedrola.com/inici2.html. Now when you click the link of the article you go to read the full article :-)

    Just a small (I think) problem. It is with pagination. If you see here : http://www.bufetepedrola.com/index.php and scroll to the bottom you will see the pagination. It works fine (onwards and backwards) except when you are in page 2 and you want to go backwards (to the first page). The link instead of showing the page (http://www.bufetepedrola.com/index.php?page1) just goes to http://www.bufetepedrola.com and then shows index.html page which is not the home of the blog. Instead of a relative url I should need a fixed one pointing to first page. Can you help me to do so?

    Thanks to Jerry and you for your help. Regards.
Connectez-vous ou Inscrivez-vous pour répondre.